javascript – C3.js – 时间序列无法解析
作者:互联网
我想使用格式为2015-09-17 18:20:34的日期和格式字符串’%Y-%m-%d%H:%M:%S’显示C3.js的时间序列图表但它无法解析.
我的代码:
var chart = c3.generate({
bindto: '#chart',
data: {
x: 'times',
columns: [
['times','2015-09-17 18:20:34','2015-09-17 18:25:42','2015-09-17 18:30:48'],
['data','1539','1546','1546','1550']
]
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d %H:%M:%S'
}
}
}
});
我收到以下错误:
02:26:44.889 Failed to parse x '2015-09-17 18:20:34' to Date object c3.min.js:1:21943
02:26:44.889 Failed to parse x '2015-09-17 18:25:42' to Date object c3.min.js:1:21943
02:26:44.890 Failed to parse x '2015-09-17 18:30:48' to Date object c3.min.js:1:21943
02:26:44.890 Failed to parse x '2015-09-17 18:20:34' to Date object c3.min.js:1:21943
02:26:44.891 Failed to parse x '2015-09-17 18:25:42' to Date object c3.min.js:1:21943
02:26:44.892 Failed to parse x '2015-09-17 18:30:48' to Date object c3.min.js:1:21943
如果我省略数据和格式的时间,但我也需要时间,它可以工作.
解决方法:
我找到了解决问题的方法:
轴对象中的格式仅用于定义日期的显示方式.如果要指定日期解析的格式,则必须在数据对象中使用xFormat.
var chart = c3.generate({
bindto: '#chart',
data: {
x: 'times',
xFormat: '%Y-%m-%d %H:%M:%S', // how the date is parsed
columns: [
['times','2015-09-17 18:20:34','2015-09-17 18:25:42','2015-09-17 18:30:48'],
['data','1539','1546','1546','1550']
]
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d %H:%M:%S' // how the date is displayed
}
}
}
});
标签:javascript,time-series,parsing,c3-js 来源: https://codeday.me/bug/20191005/1856809.html