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.

Dataset data should be an object, not an array to ensure alignment with the labels

See original GitHub issue

Feature Proposal

We should be able to specify the data in a dataset as an object that has the values keyed against the labels of the chart.

Feature Use Case

The current implementation works like this:

chart.data.labels = ["A","B","C"];
chart.data.datasets = [{data: [10,0,3]}];

This means you have to make sure that your dataset data array must be zero filled and populated in the same order as the label array. This adds unnecessary complexity to the code that builds the chart data object.

I have run into an issue creating a multiple series from an odata source. In odata, there is no guaranty that you get a data point if the value is zero, which results in this:

chart.data.labels = ["A","B","C"];
chart.data.datasets = [{data: [10,3]}];

This obviously results in an invalid chart, as A is supposed to be 10, B is supposed to be 0 and C is supposed to be 3.

Imagine if the dataset could be specified as an object instead of an array. This would make dataset building MUCH easier and less error prone.

chart.data.labels = ["A","B","C"];
chart.data.datasets = [{data: "A":10,"C":5}]

Possible Implementation

The chart.js library could maintain backward compatibility by detecting whether the dataset data property is an object or an array.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kurklecommented, Mar 16, 2019

{data: "A":10,"C":5} is not valid js.

Added support for you second example in #6106. Shown there: CodePen It would need support from maintainers / other contributors to make it. I think we all agree to the idea of parsing once and using parsed data everywhere, but the implementation is all my doing and has not been discussed much.

0reactions
PaulWielandcommented, Apr 22, 2019

@kurkle, can this be amended to work for line charts as well?

I ran into an issue trying to plot a forecast line. In this case I have 12 Months on the X axis and I want to plot a line that goes from today forward only. With the current behavior, it starts at the beginning of the X axis and stops when it runs out of points.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Labeling: The Authoritative Guide - Scale AI
Axis alignment is critical. Ensure that the alignment of your bounding boxes is on the same axis for objects of the same class....
Read more >
Computation — xarray 0.7.2 documentation
DataArray objects are automatically align themselves (“broadcasting” in the numpy parlance) by dimension name instead of axis order. With xarray, you do not...
Read more >
python - Get labels from dataset when using tensorflow ...
My images are organized in directories having the label as the name. The documentation says the function returns a tf.data.Dataset object. If ...
Read more >
Computation — xarray 0.9.2 documentation
DataArray objects are automatically align themselves (“broadcasting” in the numpy parlance) by dimension name instead of axis order. With xarray, you do not...
Read more >
xarray: N-D labeled Arrays and Datasets in Python
The pandas DataFrame and Series objects provide unparalleled analysis tools for data alignment, resampling, grouping, pivoting, ...
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