question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error concatenating grouped bar charts: Javascript Error: Undefined data set name

See original GitHub issue

When I tried to concatenate two grouped bar charts, it throws error "Javascript Error: Undefined data set name: “scale_concat_1_child_main”

Example can be reproduced using the grouped bar chart example (https://altair-viz.github.io/gallery/grouped_bar_chart.html)

import altair as alt
from vega_datasets import data
source = data.barley()
test = alt.Chart(source).mark_bar().encode(
    x='year:O',
    y='sum(yield):Q',
    color='year:N',
    column='site:N'
)
test & test

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
joelostblomcommented, Feb 22, 2021

Details of why this is not working can be found in https://github.com/vega/vega-lite/issues/4680, specifically this comment. It only happens when VegaLite tries to reference the same data set in two concatenated charts. A workaround is to resort the data (e.g. df.sample(df.shape[0])), so that VegaLite creates to separate data source references:

import altair as alt
from vega_datasets import data
source = data.barley()
test = alt.Chart(source).mark_bar().encode(
    x='year:O',
    y='sum(yield):Q',
    color='year:N',
    column='site:N'
)
test & test.properties(data=source.sample(source.shape[0]))

image

The obvious caveat is that if you are doing something that depends on the order of your data, this is not a good idea, but for concatenated charts this should be less of an issue as long as the dimensions are shared.

@zhanjiezhu Would you mind closing this issues as it is already tracked upstreams in Vega-Lite in the linked issues and there is no fix needed in Altair?

1reaction
torreswebcommented, Jun 24, 2020

I found a workaround for that. You need to create each group of bar columns with a graph and then concatenate these graphs, sharing Y scale and hiding/unhiding this axis.

Read more comments on GitHub >

github_iconTop Results From Across the Web

datasets is undefined when trying to access bars from chart.js
The problem is the library version. In my example and the stack example we use the library: cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/ ...
Read more >
Grouped Bar Charts - Salesforce Help
Use a grouped bar chart when you have multiple groupings, and you want to compare values within a secondary grouping, but not the...
Read more >
Google Visualization API Reference | Charts
Returns the identifier of a given column specified by the column index in the underlying table. For data tables that are retrieved by...
Read more >
Expressions | Vega
In addition, function calls involving nested properties ( foo.bar() ) are not allowed. Instead, the expression language supports a collection of functions ...
Read more >
Column State - JavaScript Data Grid
Non-stateful attributes do not change from what is set in the Column Definition (e.g. once the Header Name is set as part of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found