Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

v2.0-dev x-axis showing ms for dataset in seconds

Open mzupan opened this issue 10 years ago • 8 comments

I have the following example

https://jsfiddle.net/d0txbo3e/1/

It adds 10 data points each a second a part. The issue is the x-axis is showing ms instead of what I'm expecting.

If i change

return moment().add(days, 's').format();

to

return moment().add(days, 'm').format();

It shows correct. My only guess is it might have something to do with the labels on the ticks and there aren't enough data points?

Thanks

mzupan avatar Jan 28 '16 16:01 mzupan

Ok it does seem to be a lack of data issue. I updated with more data and getting the results I'd expect.

https://jsfiddle.net/d0txbo3e/2/

mzupan avatar Jan 28 '16 17:01 mzupan

Also another question.. in the

https://jsfiddle.net/d0txbo3e/2/

You'll notice there is a padding where the last value isn't at the end of the graph. On my test with a lot more data it seems even worse

screen shot 2016-01-28 at 10 28 31 am

mzupan avatar Jan 28 '16 18:01 mzupan

@mzupan you can set a hard end point with

scales: {
    xAxes: [{
        time: {
            max: // max time value here.
        }
    }]
}

etimberg avatar Jan 28 '16 22:01 etimberg

@etimberg thanks for the quick reply. I updated this with the example with setting a max for time

https://jsfiddle.net/d0txbo3e/4/

I'm not seeing any changes but still see the shifting and showing empty data.

mzupan avatar Jan 28 '16 22:01 mzupan

Might it be linked to https://github.com/nnnick/Chart.js/pull/1825 ?

Dergonic avatar Jan 29 '16 07:01 Dergonic

@Dergonic looks like its the same issue

mzupan avatar Jan 29 '16 11:01 mzupan

@mzupan take a look at #1950

I've updated your fiddle at https://jsfiddle.net/kfts0jdg/1/

As an immediate fix for the label issue you can add the following to your config

{
    time: {
        displayFormats: {
            millisecond: 'h:mm:ss.SSS a'
        }
    }
}

etimberg avatar Jan 30 '16 21:01 etimberg

Closing as #1950 was merged

etimberg avatar Feb 06 '16 13:02 etimberg