CSV文件中的日期字段在c3js时间序列图表中不起作用

时间:2016-01-06 23:29:44

标签: csv c3.js

当我在CSV文件中有日期字段时,c3js图表无法正常显示。 我已将x轴设置为类型时间序列。 CSV文件中只有两列。 “日期”和“计数”,例如

Date,Count
1996-12-20,1
1997-01-31,2
1997-01-31,3
1997-05-07,4
1997-10-03,5
1997-12-02,6
1997-12-02,7
<html>
<link href="http://c3js.org/css/c3-f750e4d4.css" media="screen" rel="stylesheet" type="text/css" />

<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"/></script>
<script type='text/javascript' src="https://rawgit.com/masayuki0812/c3/master/c3.js"></script> <!-- This one allows for oninit -->

<div class='chart'>
<div id='chart'></div>
</div>

<head>
    <title>Data from CSV file</title>

<script>
var chart = c3.generate({
    bindto: '#chart',
    data: {
        x: 'Date', //the x-axis
        x_Format: '%Y-%m-%d', // 'xFormat' can be used as custom format of 'x', default '%Y-%m-%d'
        url: '/dates.csv', //it won't work locally. You need to upload it to a web server
    },
    x: {
        type: 'timeseries', //date format in CSV file needs to be 2000-06-14
    }
});

</script>
</head>

<body>
</body>
</html>

这是显示的内容: No dates shown on X axis

1 个答案:

答案 0 :(得分:1)

我忘了在x:

之前添加轴
axis: {
    x: {
        type: 'timeseries', //date format in CSV file needs to be 2000-06-14
    }
}

现在它运作正常。