Highcharts动态添加系列 [英] Highcharts add series dynamically

查看:173
本文介绍了Highcharts动态添加系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一些系列(我从一个webservice的系列数据作为3dim数组(并返回它作为json) - 我不知道我会得到的系列数,所以我必须动态加载系列数据)。

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).

在javascript中,我正在构建一个对象:(像这个highstock示例: http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software /highcharts.com/tree/master/samples/stock/demo/compare/

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/)

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();

但是图表绘制的系列很奇怪,并且没有转换为到时间戳的日期。

我从webservice的图表数据有任何问题吗?

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?

这是我的代码: http:// jsfiddle。 net / DGdaf / 2 /

感谢您的帮助。

EDIT

图表似乎会忽略timeline / zoom值的所有默认值。
我不知道为什么不显示这些组件。

问题可能是,我在初始化后绘制图表?

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

我不确定是否加载了太多的数据或内容。我不能动态创建我的系列。

EDIT2
I am not sure if I am loading too much data or something. I cant create my series dynamically.

for(i=0; i<seriesOptions.length; i++){
        chart.addSeries({                        
            name: seriesOptions[i].name,
            data: seriesOptions[i].data
        }, true);

    };


推荐答案

为您的yAxis设置:

Set for your yAxis:

yAxis: {
    type: 'datetime'
}

查看小提琴

编辑:
时间轴/ zoom
http:// jsfiddle.net/DGdaf/5/

编辑:
当图表准备就绪时,使用回调添加系列。但是,为什么在创建图表时不添加这些系列?

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();
    });

这篇关于Highcharts动态添加系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆