Highchart事件LOAD无法正常工作

时间:2015-09-15 07:52:09

标签: javascript angularjs asp.net-mvc highcharts

function drawGraph($scope) {
    //console.log("in draw graph");
    //console.log(graphName);
    //console.log($scope.chartCategories);
    //console.log($scope.chartSeries);
    $scope.chartConfig = {
        chart: {
            type: 'spline',
            animation: Highcharts.svg, // don't animate in old IE
            marginRight: 10,
            events: {
                load: function () {

                    // set up the updating of the chart each second
                    var series = this.series[0];
                    setInterval(function () {
                        var x = (new Date()).getTime(), // current time
                            y = Math.random();
                        series.addPoint([x, y], true, true);
                        console.log(x + y);
                    }, 1000);
                }
            }
        },
        title: {
            text: 'Live random data'
        },
        xAxis: {
            type: 'datetime',
            tickPixelInterval: 150
        },
        yAxis: {
            title: {
                text: 'Value'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function () {
                return '<b>' + this.series.name + '</b><br/>' +
                    Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
                    Highcharts.numberFormat(this.y, 2);
            }
        },
        legend: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        series: [{
            name: 'Random data',
            data: (function () {
                // generate an array of random data
                var data = [],
                    time = (new Date()).getTime(),
                    i;

                for (i = -19; i <= 0; i += 1) {
                    data.push({
                        x: time + i * 1000,
                        y: Math.random()
                    });
                }
                return data;
            }())
        }]
    }
}

每件事都很好。图表正在创建等等,但唯一的问题是图表没有动态变化,即我认为图表中的加载事件:{}没有执行或者因为它甚至没有登录控制台。请帮助我。同样的事情是在Here

运行

2 个答案:

答案 0 :(得分:1)

尝试在更新数据后重新绘制图表。

load: function() {

    // set up the updating of the chart each second
    var series = this.series[0];
    var chart = this;
    setInterval(function() {
        var x = (new Date()).getTime(), // current time
            y = Math.random();
        series.addPoint([x, y], true, true);
        chart.redraw();
        console.log(x + y);
    }, 1000);
}

答案 1 :(得分:1)

它看起来像是highcharts-ng中的一个错误。请参阅相关主题:https://github.com/pablojim/highcharts-ng/search?q=load&type=Issues&utf8=%E2%9C%93