加载新数据到C3.js折线图

Loading new data to a C3.js line chart

本文关键字:C3 js 折线图 数据 新数据 加载      更新时间:2023-09-26

我试图动态更新C3.js折线图使用一个函数,从数据库中获得一组x和y值。我试图用来插入数据的函数是:

function insertGraph(yAxis, xAxis, Header) {
    setTimeout(function () {
        console.log("starting");
        chart.load ({
            bindto: "#graph",
            xs: {
                'y':'x'
            },
                columns: yAxis, xAxis   
        });
    }, 100);
}

传递给函数的数据看起来像这样:桠溪:

["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);
}