c3js / c3

:bar_chart: A D3-based reusable chart library
http://c3js.org
MIT License
9.34k stars 1.39k forks source link

Wrong x-values for year-week timeseries chart for some "singular" years #2676

Open gibbopotam opened 5 years ago

gibbopotam commented 5 years ago

Expected behavior:

Screen Shot 2019-08-09 at 11 05 13 AM

The same chart but the year is changed to 2018:

Screen Shot 2019-08-09 at 11 05 53 AM

As one can see the data points moved one week earlier on the chart. There're other "singular" years when this happens: 2007, 2024, 2029, 2035, ...

This is also seen on an older version of C3: 0.4.14

The code used (for convenience):

var chart = c3.generate({
    data: {
        x: 'x',
        xFormat: '%Y-%W',
        columns: [
            ['x', '2018-2', '2018-3', '2018-4'],
            ['data1', 1, 2, 3],
        ]
    },
    axis: {
        x: {
            type: 'timeseries',
            tick: {
                format: '%Y-%W'
            }
        }
    }
});
panthony commented 5 years ago

@gibbopotam Not sure if this is the cause but be careful with %Y-%W has it may be invalid.

I don't know the notation using d3 but for exemple with moment we are talking about Week year and it has a different notation.

Which is different than YYYY and it may yield different result.

gibbopotam commented 5 years ago

@panthony Yeah, it looks like the use of %W isn't documented though present in d3 (where both %w and %W are present but c3 rejects %w altogether). Still nice to have, and it works almost fine save those singular years.