HighChart:更新组柱形图

时间:2016-05-17 09:55:05

标签: javascript highcharts

例如,我有一个如下图表

$("#tester").highcharts({
    chart: {
        type: 'column',
        height:320
    },
    series: [{name: 'Postive',data: sPositiveTotal}, 
            {name: 'Neutral',data: sNeutralTotal}, 
            {name: 'Negative',data: sNegativeTotal}]
});

我尝试用按钮更新数据,我做

var SentimentChart = $("#tester").highcharts();
SentimentChart.series[0].setData([{name: 'Postive',data: sPositiveTotal}, {name: 'Neutral',data: sNeutralTotal}, {name: 'Negative',data: sNegativeTotal}]);

但它不像我,除了,我怎么能正确更新它?

小提琴示例:http://jsfiddle.net/cmeubLr2/1/

1 个答案:

答案 0 :(得分:2)

在特定系列中调用setData method,因此您必须为每个单独的系列进行更新。它还只需要数据,而不是系列选项。

例如(JSFiddle):

changeData.series[0].setData([124, 5435, 16434, 129.2, 144.0, 176576.0, 176535.6, 148.5, 216.4, 194.1, 95.6, 54.4]);
changeData.series[1].setData([8753.6, 66.8, 98.5, 93.4, 175606.0, 84.5, 107655.0, 104.3, 91.2, 83.5, 106.6, 92.3]);
// ...

如果您还要更新选项,可以使用update代替JSFiddle):

changeData.series[0].update({
    name: 'Beijing',
    data: [124, 200, 200, 129.2, 144.0, 200.0, 200.6, 148.5, 216.4, 194.1, 95.6, 54.4]
});