How to remove gaps in C3 timeseries chart?

最后都变了- 提交于 2020-01-06 07:23:28

问题


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.


回答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/



来源:https://stackoverflow.com/questions/32275222/how-to-remove-gaps-in-c3-timeseries-chart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!