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.

Add support for ticks.source: 'data' to category scale

See original GitHub issue

Expected Behavior

I expect that using the new 2.7 feature of defining a bar chart using arrays of objects with x/y values e.g. [{x: ..., y: ...}, ...] to generate the x labels and y values on a barchart as per the docs here: http://www.chartjs.org/docs/latest/charts/bar.html

You can also specify the dataset as x/y coordinates.

data: [{x:'2016-12-25', y:20}, {x:'2016-12-26', y:10}]

Current Behavior

See interactive pen here: https://codepen.io/ortonomy/pen/NaxVeZ

Providing a data.dataset with an array of x/y objects (e.g. data: [{x: ..., y: ...}, ...]) does not render all data points. It only renders a single bar, using the first value of the data set.

The only way that I can get it to display multiple values, is by providing the labels: [...] property to the data object. And even then, the number of bars displayed is only equal to the length of labels: [...].

I may be wrong here, but from what I can tell, the reason for providing the array of x/y objects is so the data itself provides the x label.

Steps to Reproduce (for bugs)

code

data: {
        // labels: ['x','x'],
        datasets: [{
            label: '# of Votes',
            data: [{x: 'label', y: 12}, {x: 'label', y: 19}, {x: 'label', y: 3}, {x: 'label', y: 5}, {x: 'label', y: 2}, {x: 'label', y: 3}]
        }]
    },

link https://codepen.io/ortonomy/pen/NaxVeZ

Context

The data coming back from my API is already in an object: {x: ..., y: ...} format so you can imagine my joy at seeing this being provided as an option. Now I have to split the data to use x: ... for labels: [...], and then y: ... for data: [...].

Environment

  • Chart.js version: 2.7.0
  • Browser name and version: Chrome 61 Mac OS X
  • Link to your project: Can’t link – is private.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
SanoLitchcommented, Sep 19, 2017

+1 Also found this bug today

1reaction
benmccanncommented, Sep 19, 2017

Yes, you still need to specify the labels. It’s at least a bit easier for you because you now only need to create the labels instead of creating the labels and transforming the data from your format to array format.

One solution to this would be to add a ticks.source: 'data' just like @simonbrunel added in the time scale in https://github.com/chartjs/Chart.js/pull/4507. And it should default to this if the user doesn’t specify any labels.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the display of chart axes - Microsoft Support
Change the number of categories between labels or tick marks · Click anywhere in the chart. This displays the Chart Tools, adding the...
Read more >
chartjs ticks callback not working - Margolis Law Firm
This sample shows how to use different tick features to control how tick labels are shown on the X axis. As to my...
Read more >
Control axis with categorical values - MATLAB - MathWorks
CategoricalRuler properties control the appearance and behavior of an x-axis, y-axis, or z-axis that shows categorical values.
Read more >
Chart Elements
On large or complex charts, drop lines help show which category a data point belongs to. Drop lines are only available on line...
Read more >
10 Position scales and axes | ggplot2
The default behaviour in ggplot2 is to convert any data values outside the scale limits to NA . This means that changing the...
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