gpt4 book ai didi

javascript - C3-折线图时间序列错误: x is not defined for id = "Dates"

转载 作者:行者123 更新时间:2023-11-30 09:39:39 25 4
gpt4 key购买 nike

我正在尝试将时间序列作为 x 轴添加到 C3 中的两线图。不幸的是,我不知道该怎么做。它给出了错误“x is not defined for id = "Dates"”,尽管我已尝试尽可能地遵循 C3 的时间序列图表示例。

这是代码,有什么想法吗?

request.addEventListener('readystatechange', function () {
if (this.readyState == 4) {
var throughputReceived = JSON.parse(this.responseText).throughputReceived,
throughputSent = JSON.parse(this.responseText).throughputSent,
date = JSON.parse(this.responseText).date,
chart,
length = throughputReceived.length;

for (var i = 0; i < length; i++) {
throughputReceived[i] /= 1000000;
throughputSent[i] /= 1000000;
// date[i] = moment(date[i]).format("YYYY MM DD hh ss");
}

throughputReceived.unshift('Throughput Received (Mbps)');
throughputSent.unshift('Throughput Sent (Mbps)');
date.unshift('Dates');

chart = c3.generate({
bindto: container,
data: {
x: date,
columns: [date, throughputReceived, throughputSent]
},
axis: {
x: {
// label: 'Test No.'
type: 'timeseries',
tick: {
format: '%Y %m %d %h %s'
}
},
y: {
label: {
text: 'Throughput (Mbps)',
position: 'outer-top'
},
tick: {
format: d3.format('.2f')
}
}
}
});
}
});

最佳答案

您定义的 x 轴错误。

您必须定义列的标题,而不是引用您的日期数组。

date.unshift('Awesome-Column');
...
data: {
x: 'Awesome-Column',
columns: [date, throughputReceived, throughputSent]
},

关于javascript - C3-折线图时间序列错误: x is not defined for id = "Dates",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41782843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com