Javascript C3JSON时间序列问题
让c3js的timeseries处理json数据时遇到问题。现在我遇到了一些错误,其中最重要的错误是“Error:Invalid value for attribute x=“NaN”。尽管我的x值采用了指定的格式,但似乎没有正确解析它们。可能是什么问题 代码如下:Javascript C3JSON时间序列问题,javascript,d3.js,c3,Javascript,D3.js,C3,让c3js的timeseries处理json数据时遇到问题。现在我遇到了一些错误,其中最重要的错误是“Error:Invalid value for attribute x=“NaN”。尽管我的x值采用了指定的格式,但似乎没有正确解析它们。可能是什么问题 代码如下: var chart = c3.generate({ data: { json: [ {"key": "2015-03-27", "value": "261"},
var chart = c3.generate({
data: {
json: [
{"key": "2015-03-27", "value": "261"},
{"key": "2015-03-28", "value": "177"},
{"key": "2015-03-29", "value": "145"},
{"key": "2015-03-30", "value": "145"},
{"key": "2015-03-31", "value": "145"},
{"key": "2015-04-01", "value": "146"},
{"key": "2015-04-02", "value": "125"},
{"key": "2015-04-03", "value": "125"},
{"key": "2015-04-04", "value": "133"},
{"key": "2015-04-05", "value": "89"},
{"key": "2015-04-06", "value": "89"},
{"key": "2015-04-07", "value": "87"},
{"key": "2015-04-08", "value": "93"},
{"key": "2015-04-09", "value": "163"},
{"key": "2015-04-10", "value": "121"},
{"key": "2015-04-11", "value": "153"},
{"key": "2015-04-12", "value": "105"},
{"key": "2015-04-13", "value": "105"},
{"key": "2015-04-14", "value": "104"},
{"key": "2015-04-15", "value": "113"},
{"key": "2015-04-16", "value": "97"},
{"key": "2015-04-17", "value": "114"},
{"key": "2015-04-18", "value": "123"},
{"key": "2015-04-19", "value": "118"},
{"key": "2015-04-20", "value": "118"},
{"key": "2015-04-21", "value": "114"},
{"key": "2015-04-22", "value": "112"},
],
keys: {
x: 'key',
xFormat: '%Y-%m-%d',
value: ['value']
},
type: 'area'
},
axis: {
y: {
label: { //ADD
text: 'Y Label',
position: 'outer-middle'
}
},
x: {
label: {
text: 'X Label',
position: 'outer-center',
type: 'timeseries',
tick: {
format: '%Y-%m-%d'
}
}
}
},
legend: {
position: 'right'
},
padding: {
bottom: 20
}
});
应该是
{"key": 20150327, "value": "261"},
由于它需要一个数字,而
-
无法解析为一个数字因此轴.x
的格式是错误的。只要更改它,它就可以正常工作:
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d'
},
label: {
text: 'X Label',
position: 'outer-center'
}
}
这解决了错误。我现在必须修复格式(),但至少我有一些类似于图表的东西。非常感谢!
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d'
},
label: {
text: 'X Label',
position: 'outer-center'
}
}