本文介紹了C3.js - 時間序列無法解析的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想使用 2015-09-17 18:20:34
格式的日期和格式字符串 C3.js
顯示時間序列圖code>'%Y-%m-%d %H:%M:%S' 但解析失敗.
I want to display a time series chart with C3.js
using a date in the format 2015-09-17 18:20:34
and the format string '%Y-%m-%d %H:%M:%S'
but it fails to parse.
我的代碼:
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
如果我在數據和格式中省略時間,它會起作用,但我也需要時間.
It works if I omit the time in the data and in the format but I need the time, too.
推薦答案
我找到了解決問題的方法:
I found the solution to my problem:
axis
對象中的格式只是定義日期的顯示方式.如果要指定日期解析的格式,則必須在 data
對象中使用 xFormat
.
The format in the axis
object is just to define how the date will be displayed. If you want to specify the format for the date parsing you have to use xFormat
in the data
object.
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
}
}
}
});
這篇關于C3.js - 時間序列無法解析的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!