如果图表是由Yii扩展程序创建的,是否可以使用chart.series[i].setData
方法更新highcharts图表?我之前没有Yii扩展使用过highcharts,并且在我通过声明的变量var chart = ...
设置图表后能够引用我的变量。我只想为Yii创建的highcharts调用setData方法...这是创建图表的当前代码:
$this->Widget('ext.highcharts.HighchartsWidget', array(
'id' => 'shop_pie',
'options' => array(
'chart' => array(
'backgroundColor' => '#efefef'
),
'colors' => $colors,
'title' => array('text' => 'Shop'),
'plotOptions' => array(
'pie' => array(
'showInLegend' => 'true',
'dataLabels' => array(
'formatter' => 'js:function(){return this.point.y}',
'distance' => -10,
'color' => '#000'
),
),
'series' => $results['series'],
)
));
我的ajax调用更新图表:
"$('#city_filter').on('change',function(e) {
$.ajax({
url: ". $quotedUrl . ",
data: { 'cities': e.val },
success: function(data) {
$('#name_span').text(data[0]);
//chart.series[0].setData(data[1]); // THIS IS WHERE I NEED TO BE ABLE TO REFERENCE THE CHART
}
});
});",
非常感谢提前。 安迪
答案 0 :(得分:2)
"$('#city_filter').on('change',function(e) {
$.ajax({
url: ". $quotedUrl . ",
data: { 'cities': e.val },
success: function(data) {
$('#name_span').text(data[0]);
var chart = $('#shop_pie').highcharts();
chart.series[0].setData(data[1]); // THIS IS WHERE I NEED TO BE ABLE TO REFERENCE THE CHART
}
});
});",