C3.js - Timeseries with time fails to parse(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 - 时间序列无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C3.js - 时间序列无法解析


- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01