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

Stacked Bar Chart with time scale - multiple issues(0-valued datapoints, time scale ordering) #5405

Closed
flxwu opened this issue Apr 11, 2018 · 7 comments · Fixed by #6576
Closed

Comments

@flxwu
Copy link

flxwu commented Apr 11, 2018

What it looks like (false behavior)

screen shot 2018-04-11 at 16 10 25

My Options

options = {
    {
        legend: {
            display: false
        },
        maintainAspectRatio: false,
        scales: {
            xAxes: [{
                stacked: true,
                title: 'time',
                type: 'time',
                gridLines: {
                    lineWidth: 2
                },
                time: {
                    unit: 'day',
                    unitStepSize: 1
                },
                ticks: {
                    maxRotation: 0
                }
            }],
            yAxes: [{
                stacked: true,
                ticks: {
                    beginAtZero: true
                }
            }]
        }
    }
}

My datasets

datasets: [{
        label: 'one',
        data: [{
                x: '2016-12-25',
                y: 20
            },
            {
                x: '2016-12-26',
                y: 10
            }
        ],
        backgroundColor: 'green'
    },
    {
        label: 'two',
        data: [{
                x: '2016-12-27',
                y: 20
            },
            {
                x: '2016-12-28',
                y: 10
            }
        ],
        backgroundColor: 'red'
    }
]
}
@flxwu flxwu changed the title Stacked Bar Chart weird Visualisation Error Stacked Bar Chart with time scale weird Visualisation Error Apr 11, 2018
@simonbrunel
Copy link
Member

Please provide a jsfiddle (or similar) that reproduces this issue, but also the Chart.js version.

@flxwu
Copy link
Author

flxwu commented Apr 12, 2018

My Chart.js version is 2.7.2.

I actually found out what caused it: You have to have every time point in every dataset and set the ones you don't use to 0 respectively - like this:

datasets: [{
        label: 'one',
        data: [{
                x: '2016-12-25',
                y: 20
            },
            {
                x: '2016-12-26',
                y: 10
            },
           {
                x: '2016-12-27',
                y: 0
            },
            {
                x: '2016-12-28',
                y: 0
            }
        ],
        backgroundColor: 'green'
    },
    {
        label: 'two',
        data: [{
                x: '2016-12-25',
                y: 0
            },
            {
                x: '2016-12-26',
                y: 0
            },
           {
                x: '2016-12-27',
                y: 20
            },
            {
                x: '2016-12-28',
                y: 10
            }
        ],
        backgroundColor: 'red'
    }
]
}

But I don't think that's the way it's supposed to work, because now, when I hover over the bottom, there come the "0" valued tooltips... but at least, the blocks aren't floating around anymore.
And I also ran in #5407 .

@flxwu
Copy link
Author

flxwu commented Apr 12, 2018

And another bug:
The order of the data tuples has to be the same on each dataset, otherwise, there are weird floating blocks again.

@flxwu
Copy link
Author

flxwu commented Apr 12, 2018

So I can't have

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

on the first dataset and

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

on the second.

@flxwu flxwu changed the title Stacked Bar Chart with time scale weird Visualisation Error Stacked Bar Chart with time scale - multiple issues(0-valued datapoints, time scale ordering) Apr 12, 2018
@alesvaupotic
Copy link

Here is my example, which acts weird on stacking and also on just hiding a series: just click the first red one (Products) and it hides all of them. https://codepen.io/alesvaupotic/pen/bvyzGR

image

image

Switch stacked: true on xAxes and yAxes and you get

image

@flxwu
Copy link
Author

flxwu commented Apr 22, 2018

Any update on this one?

@stukdev
Copy link

stukdev commented Nov 14, 2018

The same issue for me...any update about this?

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