How to remove gaps in C3 timeseries chart?
Asked Answered
L

1

0

I have a timeseries chart created with C3. The chart has time gaps in the data, and this is very noticeable with a bar chart.

Is it possible to remove the gaps? I render the chart as shown below. Notice how there's a gap between 2013-01-03 and 2013-01-06

var chart = c3.generate({
    data: {
        x: 'x',
        type: 'bar',
        columns: [
            ['x', '2013-01-01', '2013-01-02', '2013-01-03', '2013-01-06', '2013-01-07', '2013-01-08'],
            ['data1', 30, 200, 100, 400, 150, 250]
        ]
    },
    axis: {
        x: {
            type: 'timeseries',
            tick: {
                format: '%Y-%m-%d'
            }
        }
    }
});

DEMO http://jsfiddle.net/4nar0rne/1/

Thank you in advance.

Leitman answered 28/8, 2015 at 16:1 Comment(0)
U
1

If you don't want the points to be plotted uniformly instead of based on the distance between the x values, you can use a category axis instead of a timseries axis.

var chart = c3.generate({
    data: {
        type: 'bar',
        columns: [
            ['data1', 30, 200, 100, 400, 150, 250]
        ]
    },
    axis: {
        x: {
            type: 'category',
            categories: ['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-06', '2013-01-07', '2013-01-08']
        }
    }    
});

However do note that you lose all the advantages of having a timeseries axes (bars spaced according to the time value, ordering, etc.).

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


And if you want the ticks to align with the center of the label you can use axis.x.centered like so

...
axis: {
    x: {
       tick: {
           centered: true
       }
       ...

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

Ustulation answered 28/8, 2015 at 21:29 Comment(1)
Thanks, this is close to what I want, however I'd like the ticks to align to the centre of the bars (like they do in timeseries charts) however have the ordering of a category chart.Leitman

© 2022 - 2024 — McMap. All rights reserved.