javascript 对多个变量使用 HighCharts setData?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14417601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using HighCharts setData for multiple variables?
提问by user1530249
High Charts API http://api.highcharts.com/highcharts#Series.setData()
High Charts API http://api.highcharts.com/highcharts#Series.setData()
javascript
javascript
....
....
$('#button').click(function() {
chart.series[0].setData( //How can I use this method to add the data?
['Firefox', 55.0],
['IE', 16.8],
['Safari', 7.5],
['Opera', 7.2],
['Others', 0.7]
);
See full code and example on jfiddle http://jsfiddle.net/bK7fh/
请参阅 jfiddle http://jsfiddle.net/bK7fh/上的完整代码和示例
回答by Nils
You forgot that set data takes an array of data, not lots of arrays.
你忘记了 set data 需要一个数据数组,而不是很多数组。
Here is an example:
下面是一个例子:
$('#button').click(function () {
chart.series[0].setData([
['Firefox', 55.0],
['IE', 16.8],
['Safari', 7.5],
['Opera', 7.2],
['Others', 0.7]
]);
});
Here is your fiddle, and working: http://jsfiddle.net/bK7fh/2/
这是你的小提琴,正在工作:http: //jsfiddle.net/bK7fh/2/