问题描述
我试图找出如何更新Highcharts饼图,但对于我来说,似乎无法正常工作。
我已经看过文档,并已能够得到一个酒吧和线和样条曲线图更新很好,但使用这个功能的饼图时,它只是无法正常工作。
我目前正在喂食in:
item.setData([[none,100]],true);
其中item等于这样的系列:
$。each(browser_chart.series,function(i,item){
if(item.name =='Browser share'){
console.log (data.browsers);
item.setData([[none,100]],true);
}
});
正如演示中所示,饼图的数据是如何格式化的。问题是它似乎无法正确读取系列。我尝试:
item.setData([\none\,100],true);
它似乎做了一些事情,但无法正确读取x和y值(这当然意味着它是错误)。
任何人都可以在这里指出我的工作方向吗?
谢谢,
p> 已编辑:
当您设置新数据时,您必须将其设置为在这种情况下所有馅饼部分的数组数组。
在我的示例我有六个类别,所以我必须为它们设置数据。
因此,在这种情况下,您必须执行以下操作: >
var seriesData = [];
$ .each(browser_chart.series,function(i,item){
if(item.name =='Browser share'){
seriesData.push([serie+ i ,someNumber]);
}
});
chart.series [0] .setData(seriesData,true);
I am trying to work out how to update a Highcharts pie chart but for the life of me cannot seem to get it working right.
I have looked over the documentation and have been able to get a bar and line and spline graph to update fine but when using this function for pie charts it just does not work.
I am currently feeding in:
item.setData([["none", 100]], true);
Where item equals the series like so:
$.each(browser_chart.series, function(i, item){
if(item.name == 'Browser share'){
console.log(data.browsers);
item.setData([["none", 100]], true);
}
});
Which as shown in the demos is how the data for a pie chart is formatted. Problem is it cannot seem to read the series correctly. I try:
item.setData([\"none\", 100], true);
And it seems to do something but cannot read the x and y values right (which of course means it's wrong).
Can anyone here point me in the direction to get this working?
Thanks,
Edited:
When you set a new data you have to set as array of arrays for all pie parts in this case.
In my Example I have six categories, so I've to set data for all of them.
So, in this case you have to do something like:
var seriesData = [];
$.each(browser_chart.series, function(i, item) {
if(item.name == 'Browser share'){
seriesData.push(["serie"+i, someNumber]);
}
});
chart.series[0].setData(seriesData, true);
这篇关于Highcharts:使用setData()更新饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!