2016-02-04 47 views
0

我使用highcharts time series,我需要添加從另一個json文件/鏈接填充的另一個數據系列,這可能嗎?在一個高圖中添加兩個json數據系列

這裏是我的代碼:

$(function() { 
    $.getJSON('myfirstjson', function (data) { 
     mydata = []; 
     $('#tvmtgm').highcharts({ 
      chart: { 
       zoomType: 'x' 
      }, 
      title: { 
       text: 'TVM/TGM' 
      }, 
      xAxis: { 
       type: 'datetime', 

       dateTimeLabelFormats : { 
        hour: '%I %p', 
        minute: '%I:%M %p' 
       } 
      }, 
      yAxis: { 
       title: { 
        text: 'Moves' 
       } 
      }, 
      legend: { 
       enabled: false 
      }, 
      plotOptions: { 
       area: { 
        fillColor: { 
         linearGradient: { 
          x1: 0, 
          y1: 0, 
          x2: 0, 
          y2: 1 
         }, 
         stops: [ 
          [0, Highcharts.getOptions().colors[0]], 
          [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')] 
         ] 
        }, 
        marker: { 
         radius: 2 
        }, 
        lineWidth: 1, 
        states: { 
         hover: { 
          lineWidth: 1 
         } 
        }, 
        threshold: null 
       } 
      }, 

      series: [{ 
       type: 'area', 
       name: 'Total vessel moves', 
       data: data 
      } 
      ] 
     }); 
    }); 
}); 

有在highcharts網站上的例子,但它們都是靜態的數據系列,我需要從JSON填充兩個數據系列的請求

+0

請參閱[本演示](http://www.highcharts.com/stock/demo/compare)。 –

回答

2

是的,你可以。當然,我希望我能理解你的問題。

This link向您展示如何添加多個y軸。 至於獲取數據。 $.when應該可以幫到你。

var data1, data2; 
$.when(
    $.getJSON(onurl1, function(data) { 
     data1 = data; 
    }), 
    $.getJSON(onurl2, function(data) { 
     data2= data; 
    }) 
).then(function() { 
    //use data1 and data2 
}); 
相關問題