Highcharts - 重绘()与新的Highcharts.chart [英] Highcharts - redraw() vs. new Highcharts.chart
问题描述
我正在努力理解更新高图表的正确方法。假设我已经绘制了图表,然后我想以某种方式更新它。例如,我可能想要更改数据系列的值,或者我可能想要启用dataLabels。
目前唯一可以找出如何这是为了改变图表选项,并使用 new Highcharts.chart
来告诉高图重绘。
然而, ,我想知道这是否可能是矫枉过正的,并且有可能在原位改变图表,而不必从头开始使用 new Highcharts.chart
。我注意到有一个 redraw()
方法,但我似乎无法完成它。
任何帮助非常感谢。
谢谢,
罗宾
示例代码如下,在底部有一个jsFiddle
$ p $ $(document).ready(function (){
chartOptions = {
图:{
renderTo:'container',
type:'area',
},
系列:[{
data:[1,2,3]
}]
};
chart1 = new Highcharts.Chart(chartOptions);
chartOptions.series [0] .data = [10,5,2];
chart1 = new Highcharts.Chart(chartOptions);
/ /以下内容似乎无效
chart1.series [0] .data = [2,4,4];
chart1.redraw();
});
http ://jsfiddle.net/sUXsu/18/
[edit]:
任何未来的观众问题,值得注意的是没有方法隐藏和显示dataLabels。下面显示了如何做到这一点: http://jsfiddle.net/supertrue/tCF8Y/
chart.series [0] .setData(data,true);
I'm struggling to understand the correct way to update a highcharts chart. Supposing I have rendered a chart, and then I want to update it in some way. For instance, I may want to change the values of the data series, or I may want to enable dataLabels.
At the moment the only way I can figure out how to do this is to alter the chart options, and use new Highcharts.chart
to tell highcharts to redraw.
However, I'm wondering whether this may be overkill and it might be possible to alter the chart 'in situ', without having to start from scratch with new Highcharts.chart
. I notice there is a redraw()
method, but I can't seem to get it to work.
Any help is very much appreciated.
Thanks,
Robin
Sample code is as follows and at the bottom there is a jsFiddle
$(document).ready(function() {
chartOptions = {
chart: {
renderTo: 'container',
type: 'area',
},
series: [{
data: [1,2,3]
}]
};
chart1 = new Highcharts.Chart(chartOptions);
chartOptions.series[0].data= [10,5,2];
chart1 = new Highcharts.Chart(chartOptions);
//The following seems to have no effect
chart1.series[0].data = [2,4,4];
chart1.redraw();
});
[edit]:
For any future viewers of this question, it's worth noting there is no method to hide and show dataLabels. The following shows how to do it: http://jsfiddle.net/supertrue/tCF8Y/
chart.series[0].setData(data,true);
The setData
method itself will call the redraw method
这篇关于Highcharts - 重绘()与新的Highcharts.chart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!