如何将多个数据序列导入Highcharts [英] How to get multiple data series into Highcharts

查看:80
本文介绍了如何将多个数据序列导入Highcharts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码有效:

  var options1 = {
图表:{
renderTo:' container1'
},
series:[{}]
};

$ .getJSON('tokyo.jsn',function(data){
options1.series [0] .data = data;
var chart = new Highcharts.Chart( options1);
});

我希望能够添加多个数据系列,因此我正在尝试引用到getJSON的'New Highcharts',但我似乎没有把它做对。以下代码无效:

  $。getJSON('tokyo.jsn',function(data){
options1.series [0] .data = data;
});
var chart = new Highcharts.Chart(options1);

我也尝试过以不同的方式解决问题,但下面的代码不起作用:

  var chart1 = new Highcharts.Chart({
图表:{
renderTo:'container1'
},
系列:[{}]
});

$ .getJSON('tokyo.jsn',function(data){
chart1.series [0] .data = data;
});

任何人都可以指出正确的方向。我需要通过执行第二次getJSON调用来支持多个数据系列,如下所示:

  $。getJSON('sydney .jsn',函数(data){
options1.series [1] .data = data;
});

我使用的JSON代码如下所示:

  [7.0,6.9,9.5,14.5,18.2,21.5,25.2,26.5,23.3,18.3,13.9,9.6] 

谢谢 解决方案

您可以使用以下解决方案该示例中的高级图表: http://www.highcharts.com/stock/demo/compare



或者先创建一个没有任何序列的空图表,然后在每个回调函数中使用 addSeries()请参阅: http://api.highcharts.com/highcharts#Chart.addSeries()


The following code works:

var options1 = {
    chart: {
        renderTo: 'container1'
    },
    series: [{}]
    };

$.getJSON('tokyo.jsn', function(data){
        options1.series[0].data = data;
        var chart = new Highcharts.Chart(options1);
    });

I want to be able to add a number of data series, so I am trying to take the reference to ‘new Highcharts’ out of the getJSON, but I don't seem to get it right. This following code does not work:

$.getJSON('tokyo.jsn', function(data){
    options1.series[0].data = data;
});
var chart = new Highcharts.Chart(options1);

I have also tried tackling it a different way but again the following code does not work:

var chart1 = new Highcharts.Chart({
    chart: {
        renderTo: 'container1'
    },
    series: [{}]
});

$.getJSON('tokyo.jsn', function(data){
    chart1.series[0].data = data;
});

Can anyone point me in the correct direction. I need to be able to support multiple data series by doing a second getJSON call like the following:

$.getJSON('sydney.jsn', function(data){
    options1.series[1].data = data;
});

The JSON code I'm using is as follows:

[ 7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6 ]

Thanks

解决方案

You can use solution used by Highcharts in that example: http://www.highcharts.com/stock/demo/compare

Or first create empty chart, without any series, and then use addSeries() function in each callback, see: http://api.highcharts.com/highcharts#Chart.addSeries()

这篇关于如何将多个数据序列导入Highcharts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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