在 HighCharts 的加载事件中更改数据点值

change data point value inside load event in HighCharts

在 HighCharts 图表中,我需要更改图表对象内的数据点。所以我使用事件属性。但以下玩具代码不起作用:

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'scatter',
            zoomType: 'xy',
            events: {
                load: function () {
         this.series[0].data[1].y=7.5;
         this.redraw();
                }
            },
        },
        series: [{type: 'scatter',
                  data:[
                    {y:10,x:1},
                    {y:8,x:2},
                    {y:9,x:3},
                    {y:7,x:4},
                    {y:7,x:5},
                        ]
                }]
    });
});

怎么了? Jfiddle 版本在这里:http://jsfiddle.net/zqhavLz9/

您可以轻松使用 this.series[0].update:

this.series[0].update({
                    data: [
                        {y:10,x:1},
                        {y:7.5,x:2},
                        {y:9,x:3},
                        {y:7,x:4},
                        {y:7,x:5},
                    ]
                });

这将自动重绘图表并更新数据:DEMO

或者您可以在调用 redraw 之前使用 this.series[0].isDirty = true:

load: function () {
                this.series[0].data[1].y=7.5;
                this.series[0].isDirty = true;
                this.redraw();
            }

这是DEMO