为什么Highstock初始化将系列变量设置为null?

时间:2013-09-25 14:08:52

标签: javascript highcharts highstock

当我使用配置对象初始化我的HighCharts StockChart时,初始化后对象中的series参数设置为null。这是为什么?

代码

//object
var myClass = {
    chartConfig: {
       //some highcharts config

       //some extra params
       url: 'getData.php'
    }
};

myClass.prototype.renderChart = function() {
    console.log(this.chartConfig.series);
    this.chart = new Highcharts.StockChart(this.chartConfig);
    console.log("=======================");
    console.log(this.chartConfig.series);
};

myClass.prototype.getSeriesData = function() {
    var self = this;
    $.getJSON(self.chartConfig.url, function(data) {
        self.chartConfig.series = data;
    });
};

var test = new myClass();
test.getSeriesData();
test.renderChart();

输出

[Object, Object, Object, animation: false]
=======================
null 

1 个答案:

答案 0 :(得分:3)

将此行this.chart = new Highcharts.StockChart(this.chartConfig);替换为this.chart = new Highcharts.StockChart($.extend({},this.chartConfig));