【发布时间】:2019-09-10 18:08:22
【问题描述】:
原始 C3.js 示例:
https://c3js.org/samples/chart_stanford.html
我的 C3.js 斯坦福图表中出现以下控制台日志错误:
c3.js:2349 无法将 x '2019-09-10 08:15:51' 解析为日期对象
在我所有的 JSON 值中。
我知道这与 xFormat 有关,我已在键中添加了它:数据区域:,但我仍然收到相同的错误。
var data = [
{
"Time": "2019-09-10 08:15:51",
"Range Gate": 26,
"Velocity": 44
},
{
"Time": "2019-09-10 08:16:51",
"Range Gate": 46,
"Velocity": 47
},
{
"Time": "2019-09-10 08:17:51",
"Range Gate": 55,
"Velocity": 50
},
{
"Time": "2019-09-10 08:18:51",
"Range Gate": 1,
"Velocity": 54
},
{
"Time": "2019-09-10 08:19:51",
"Range Gate": 11,
"Velocity": 54
}
];
这个数据集也是如此:
var data = [
{
"Time": "08:15:51",
"Range Gate": 26,
"Velocity": 44
},
{
"Time": "08:16:51",
"Range Gate": 46,
"Velocity": 47
},
{
"Time": "08:17:51",
"Range Gate": 55,
"Velocity": 50
},
{
"Time": "08:18:51",
"Range Gate": 1,
"Velocity": 54
},
{
"Time": "08:19:51",
"Range Gate": 11,
"Velocity": 54
}
];
var chart = c3.generate({
size: {
height: 600,
width: 800 * 1.12
},
data: {
json: data,
mimeType: 'json',
epochs: 'Velocity',
keys: {
x: 'Time',
xFormat: '%H:%M:%S',
value: ['Range Gate', 'Velocity']
},
type: 'stanford'
},
legend: {
hide: true
},
point: {
focus: {
expand: {
r: 5
}
},
r: 2.5
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%H:%M:%S'
},
show: true,
label: {
text: 'Time',
position: 'outer-center'
},
min: 0,
max: 61,
padding: {
top: 0,
bottom: 0,
left: 0,
right: 0
},
},
y: {
show: true,
label: {
text: 'Range Gate',
position: 'outer-middle'
},
min: 0,
max: 60,
tick: {
values: d3.range(0, 65, 10)
},
padding: {
top: 5,
bottom: 0,
left: 0,
right: 0
},
}
},
stanford: {
scaleMin: 1,
scaleMax: 10000,
scaleFormat: 'pow10',
padding: {
top: 15,
right: 0,
bottom: 0,
left: 0
}
}
});
c3.js:2349 无法将 x '2019-09-10 08:15:51' 解析为日期对象
c3.js:2349 无法将 x '2019-09-10 08:16:51' 解析为日期对象
等等
【问题讨论】:
-
您的值包含完整的日期+时间,但您没有解析 y-m-d 元素的占位符。
-
嗨彼得,我也试过只使用 h-m-s 数据集,结果相同。
标签: javascript d3.js c3.js