Search code examples
javascriptc3

C3 subchart won't start with initial value on timeseries chart


I am running into the problem where my subchart won't start with an initial value when I am using a timeseries chart. I think that the format property on x.tick is somehow messing it up. Any help would be appreciated.

The code below is an example of the issue that I am having:

var day1 = new Date();
day1.setDate(day1.getDate() - 7);
var day2 = new Date();
day2.setDate(day2.getDate() - 6);
var day3 = new Date();
day3.setDate(day3.getDate() - 5);
var day4 = new Date();
day4.setDate(day4.getDate() - 4);
var day5 = new Date();
day5.setDate(day5.getDate() - 3);


var chart = c3.generate({
    data: {
        x: 'x',
        columns: [
            ['x', day1, day2, day3, day4, day5],
            ['data1', 30, 200, 100, 400, 150],
            ['data2', 130, 340, 200, 500, 250]
        ]
    },
    axis: {
        x: {
            type: 'timeseries',
            extent: ['05-23', '05-24'],
            tick: {
                format: '%m-%d'
            }
        }
    },
    subchart: {
        show: true
    }
});

Solution

  • Just modify your extent to give the limits in a YYYY-MM-DD format

    extent: ['2015-05-23', '2015-06-23'],
    

    Fiddle - http://jsfiddle.net/pL8jndft/