我正在尝试使用 c3.js 时间序列折线图(URL:http://c3js.org/samples/timeseries.html)。唯一的区别是我使用 CDN 链接到 js 文件而不是下载它们。但是我不断收到以下错误
Chrome Uncaught Error :没有为 id = "date"定义 x。
火狐 错误:没有为 id = "date"定义 x。
throw new Error('x is not defined for id = "' + id + '".'); | ----------+
html文件如下
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.css"/>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.js"></script>
<script>
var dates = ['20130101', '20130102', '20130103', '20130104', '20130105', '20130106'];
var sample = [30, 200, 100, 400, 150, 250];
var chart = c3.generate({
bindto: '#chart',
data: {
x:'Dates',
x_format:'%Y%m%d',
columns: [
//['Dates'].concat(dates),
//['Sample'].concat(sample)
['date', '20130101', '20130102', '20130103', '20130104', '20130105', '20130106'],
['sample', 30, 200, 100, 400, 150, 250]
]
},
axis: {
x: {
type : 'timeseries'
}
}
});
</script>
</head>
<body>
<div id="chart"></div>
</body>
</html>
我不确定为什么会收到与日期相关的错误。我尝试在 C3 参数中使用实际数据值并将数据作为变量传递。非常感谢任何帮助
最佳答案
您的dates
数组需要第一个值为“set”的名称/id,例如:
var dates = ['Dates', '20130101', '20130102', '20130103', '20130104', '20130105', '20130106'];
data
对象的 x
属性需要与此匹配。在上面的代码中,您有不同的值:Dates
和 date
。
data: { x:'Dates',
您在 concat
尝试中更接近了。
关于javascript - C3 js折线图获取日期错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30338691/