javascript - 如何将数据附加到 c3.js 中的系列?
问题描述
当数据来自mqtt
通道时,我有一个要更新的图表。但是,我看不到如何将steps
系列附加到正确的消息上。
var chart = c3.generate({
bindto: '#epoch-report',
data: {
columns: [
['steps',]
]
},
axis:{
x: {
max: .1,
label: {
text: "Epoch"
}
},
y: {
max: .1,
label: {
text: "Step",
}
}
}
});
if (topic == "/epoch/update") {
var j = JSON.parse(new TextDecoder("utf-8").decode(payload));
var msg = "<br> Epoch: " + j.id + " steps: " + j.steps + " winner: " + j.winner;
document.getElementById('epoch-report').innerHTML += msg;
console.log("Now I want to add data to ");
console.log(chart.data.values);
} else if (topic == "/epoch/setup") {
var j = JSON.parse(new TextDecoder("utf-8").decode(payload));
console.log("setting up epoch dash with max steps " + j.maxsteps);
}
我似乎无法访问chart.data.columns['step']
或类似的东西。我该如何添加steps
?