Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with x axis stacking for a stacked bar chart #5072

Closed
cmodiano opened this issue Dec 22, 2017 · 6 comments · Fixed by #6576
Closed

Issue with x axis stacking for a stacked bar chart #5072

cmodiano opened this issue Dec 22, 2017 · 6 comments · Fixed by #6576

Comments

@cmodiano
Copy link

cmodiano commented Dec 22, 2017

Hi,

I'm trying to build a stacked bar chart based on a time series x axis.
The chart doesn't seem to stack correctly on the x axis, I don't know if I missed something or it's a bug.
Any help will be much appreciate, here is a Fiddle to illustrate the problem.

https://jsfiddle.net/1kLyyjfp/

Thanks

@cmodiano cmodiano changed the title Issue with x axis stacking for a stacked bat chart Issue with x axis stacking for a stacked bar chart Dec 22, 2017
@simonbrunel
Copy link
Member

@cmodiano I'm not sure what are your expectations in this case, maybe #4994 (fiddle) fixed it. But your issue might also be the way you setup your data, I'm not sure it works well to define data like [{x, y}] with the stack feature. You could try to use labels + data[y] instead:

data: {
  labels: ['2017-12-22 08:59', '2017-12-22 09:00'],
  datasets: [{
    data: [2, 18]
  }, {
    data: [0, 2]
  }, {
    data: [0, 4]
  }, 
  //...
}   

@cmodiano
Copy link
Author

@simonbrunel You add a 0 value for the y when the timestamp data does not exist, is it mandatory? If yes this will mean I have to alter the data retrieved from the database before generating the chart. Is it possible to make Chartjs auto add the 0 values for missing timestamps?
I'm not sure the issue you're linking to is related to mine.

Thanks

@simonbrunel
Copy link
Member

I guess it should work the way you set your data, but I'm not sure the actual code can handle it, that's why I suggest the other format. I think it would help if you provide a picture of the result you are expecting.

@cmodiano
Copy link
Author

I tried and whatever format is used it is necessary that each serie has a value for each timestamp.
It would be nice if a 0 value could be added automatically if none is provided. I think it must be a really common use case.

@AimForNaN
Copy link

Came across this issue today.

Here is what I get: https://jsfiddle.net/kbn1L9w1/
Here is what I expect: https://jsfiddle.net/5a40pn0j/

The only difference with the two scripts is that I manually fill in data so that both data sets match the same length, though I was expecting the script to do that work for me. Indeed, the green bar should not be extending into a category that it is not part of.

@benmccann
Copy link
Contributor

It looks like this PR might be for the same issue: #5298

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants