我正在尝试使用从数据库获取一组x和y值的函数动态更新C3.js折线图。我试图用来插入数据的函数是:
function insertGraph(yAxis, xAxis, Header) {
setTimeout(function () {
console.log("starting");
chart.load ({
bindto: "#graph",
xs: {
'y':'x'
},
columns: yAxis, xAxis
});
}, 100);
}
传递给函数的数据如下所示:
yAxis:
["y", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
xAxis:
["x", 0, 131.35, 26971.3, 27044.75, 27351.4, 27404.483333333334, 27419.416666666668, 33128.96666666667, 33549.13333333333, 34049.48333333333, 77464.26666666666, 77609.71666666666, 174171.85, 259166.98333333334]
标头:
MakeModeChange #just a string
我知道我在这里做的事情根本上是错误的,但是任何帮助都将不胜感激
最佳答案
万一有人需要它,我设法弄清楚了我的问题。这完全取决于您如何处理“列”部分(需要在[]
中进行绑定)。这是固定代码,以防万一:
function insertGraph(yAxis, xAxis, Header) {
setTimeout(function () {
chart.load ({
bindto: "#graph",
xs: {
'y':'x'
},
columns: [
yAxis,
xAxis
]
});
}, 100);
}
关于javascript - 将新数据加载到C3.js折线图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30461946/