2

我已经使用 highcharts 制作了一个图表,我想重新绘制我的 highcharts,但是这行代码让我感到困惑并且不允许我添加现有数据。这会添加随机数据,但我想要的是从 javascript 添加数据...

// Add the new series.
chart.addSeries({ data: Highcharts.map(Array(12), Math.random) }, false);

其他代码:

 $(".test").change(function() {
    var value = this.getAttribute("value");
    while (chart.series.length > 0) {
        chart.series[0].remove(true);
    }
    if (value == 'a') {
        loadA(chart);
    } else if (value == 'b') {
        chart.xAxis[0].update({categories: ['Sun', 'Mon', 'Tue']});
        chart.addSeries({
            name: 'Rainfall4',
            type: 'column',
            color: '#FF00FF',  
            data:[100, 280, 300, 490, 670, 900]             
        });            
        chart.yAxis[0].setTitle({ text: "Raw" });
    } else if (value == 'c') {
        chart.xAxis[0].update({categories: ['Oranges',  'Pears', 'Pinneaples',  'other']});

这是 Jsfiddle:

http://jsfiddle.net/VnCgx/9/

想要类似的东西

  chart.series[0].setData([129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4] );
});
4

1 回答 1

3

这就是你需要的

function redraw(chart) {

// Delete all the series.
/*
while (chart.series.length > 0) {
    chart.series[0].remove(false);
}
*/

// Add the new series.

 chart.series[0].setData([129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5,   106.4]);
chart.redraw();
于 2013-07-05T10:07:28.067 回答