我想要更新图表,因为数据来自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
?