【问题标题】:Date field from CSV file doesn't work in c3js timeseries chartCSV 文件中的日期字段在 c3js 时间序列图中不起作用
【发布时间】:2016-01-06 23:29:44
【问题描述】:

当我在 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>

这是显示的内容:

【问题讨论】:

    标签: csv c3.js


    【解决方案1】:

    我忘记在 x 之前添加轴了:

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

    现在它可以正常工作了。

    【讨论】:

      猜你喜欢
      • 2021-01-03
      • 2021-07-03
      • 2020-05-27
      • 1970-01-01
      • 2020-01-31
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      • 2020-06-11
      相关资源
      最近更新 更多