json Highcharts 动态添加系列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17232539/
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
Highcharts add series dynamically
提问by spyfx
I want to add some series (I get the series data from a webservice as a 3dim array (and returning it as json) - I dont know the number of series I will get, so I have to load the series data dynamically).
我想添加一些系列(我从 webservice 获取系列数据作为 3dim 数组(并将其作为 json 返回) - 我不知道我将获得的系列数量,所以我必须动态加载系列数据)。
In javascript I am building an object: (like this highstock example: http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/stock/demo/compare/)
在javascript中,我正在构建一个对象:(就像这个highstock示例:http: //jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/stock/demo/比较/)
seriesOptions[i] = {
name: namearray[i],
data: dataarray
};
e.g. result: [Object { name="Series", data=[[1041375600000, 29,9]]}]
I was trying to add the series like this:
我试图添加这样的系列:
$.each(seriesOptions, function (itemNo, item) {
chart.addSeries({
name: item.name,
data: item.data
}, false);
});
chart.redraw();
But the chart draws the series kinda weird and doesnt convert to timestamp to date.
Are there any problems with my chart data from the webservice?
但是图表绘制的系列有点奇怪,并且没有转换为时间戳。
我的网络服务图表数据有问题吗?
Here is my code: http://jsfiddle.net/DGdaf/2/
这是我的代码:http: //jsfiddle.net/DGdaf/2/
Thanks for any help so far.
感谢您到目前为止的任何帮助。
EDIT
It seems like the chart ignoeres all the default values of timeline/zoom value.
I have no idea why it doesnt display these components.
The problem could be, that I am drawing the chart after the initialization?
编辑
图表似乎忽略了时间线/缩放值的所有默认值。我不知道为什么它不显示这些组件。
问题可能是,我在初始化后绘制图表?
chart = new Highcharts.Chart(options);
But I have to do it cause of the dynamic series loading.
但由于动态系列加载,我必须这样做。
EDIT2
I am not sure if I am loading too much data or something. I cant create my series dynamically.
EDIT2
我不确定我是否加载了太多数据或其他东西。我无法动态创建我的系列。
for(i=0; i<seriesOptions.length; i++){
chart.addSeries({
name: seriesOptions[i].name,
data: seriesOptions[i].data
}, true);
};
回答by Pawe? Fus
Set for your yAxis:
为您的 yAxis 设置:
yAxis: {
type: 'datetime'
}
See fiddle
见小提琴
EDIT: Timeline / zoom http://jsfiddle.net/DGdaf/5/
编辑:时间轴/缩放 http://jsfiddle.net/DGdaf/5/
Edit: Use callback to add series, when chart is ready. However, why don't you add these series when chart is created?
编辑:当图表准备好时,使用回调添加系列。但是,为什么在创建图表时不添加这些系列?
chart = new Highcharts.Chart(options, function(ch) {
$.each(seriesOptions, function (itemNo, item) {
ch.addSeries({
name: item.name,
data: item.data
}, false);
});
chart.redraw();
});

