当我使用配置对象初始化我的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
答案 0 :(得分:3)
将此行this.chart = new Highcharts.StockChart(this.chartConfig);
替换为this.chart = new Highcharts.StockChart($.extend({},this.chartConfig));