2014-10-30 86 views
1

即時通訊有一些問題,添加系列yAxis與不同的ID在highcharts。HighCharts。添加系列yAxis與編號

我已經做出了表率:

$(function() { 

     $('#graf').highcharts({ 
      chart: { 
       zoomType: 'xy' 
      }, 
      title: { 
       text: '' 
      }, 
      subtitle: { 
       text: '' 
      }, 
      xAxis: [{type: 'datetime', 
        title: { 
         text: 'Date' 
        }}], 
      yAxis: [], 
        series : [] 
        , 
      tooltip: { 
       shared: true 
      }, 
      legend: { 
       enabled: true, 
       align: 'left', 
       backgroundColor: '#FFFFFF', 
       borderColor: 'grey', 
       borderWidth: 1, 
       layout: 'vertical', 
       verticalAlign: 'top', 
       y: 0, 
       shadow: true 
      } 
     }); 


var chart = $('#graf').highcharts(); 
$('#add').click(function() { 
    chart.addAxis({ // Secondary yAxis 
     id: "asd", 
     title: { 
      text: 'Rainfall' 
     }, 
     lineWidth: 2, 
     lineColor: '#08F', 
     opposite: true 
    });  
    chart.addAxis({ // Secondary yAxis 
     id: "abc", 
     title: { 
      text: 'Rainfall' 
     }, 
     lineWidth: 2, 
     lineColor: '#08F', 
     opposite: true 
    });  
    chart.addSeries({ 
     name: 'Rainfall', 
     type: 'column', 
     color: '#08F', 
     yAxis: "asd", 
     data: [ [Date.UTC(1970, 9, 27), 0 ], 
      [Date.UTC(1970, 10, 10), 0.6 ], 
      [Date.UTC(1970, 10, 18), 0.7 ], 
      [Date.UTC(1970, 11, 2), 0.8 ], 
      [Date.UTC(1970, 11, 9), 0.6 ]] 
    }); 
    $(this).attr('disabled', true); 
    $('#remove').attr('disabled', false); 
}); 
}); 

的jsfiddle:http://jsfiddle.net/5f6b6mu9/

我有Y軸ID爲 「ASD」 和 「ABC」。 當試圖添加一系列的「asd」yAxis它不起作用。 Uncaught TypeError:無法讀取未定義的屬性「長度」。

這裏是什麼在我的網頁怎麼回事上限: http://i61.tinypic.com/8yx7cw.jpg

如果我改變這兩個y軸ID相同的ID,它的工作,但那不是重點。

有什麼建議嗎?謝謝

回答

1

這很簡單。

添加系列後立即添加yAxis對應的系列。

chart.addAxis({ // Secondary yAxis 
      id: "asd", 
      title: { 
       text: 'Rainfall' 
      }, 
      lineWidth: 2, 
      lineColor: '#08F', 
      opposite: true 
     },false); 
     chart.addSeries({ 
      name: 'Rainfall', 
      type: 'column', 
      color: '#08F', 
      yAxis: "asd", 
      data: [ [Date.UTC(1970, 9, 27), 0 ], 
       [Date.UTC(1970, 10, 10), 0.6 ], 
       [Date.UTC(1970, 10, 18), 0.7 ], 
       [Date.UTC(1970, 11, 2), 0.8 ], 
       [Date.UTC(1970, 11, 9), 0.6 ]] 
     }); 

     chart.addAxis({ // Secondary yAxis 
      id: "abc", 
      title: { 
       text: 'Rainfall' 
      }, 
      lineWidth: 2, 
      lineColor: '#08F', 
      opposite: true 
     },false); 

這裏,我已經更新了fiddle

+0

我不能這樣做,因爲我的系列與XMLHttpRequest的動態加載。無論如何,我這樣做是固定的: 而不是創建圖表,然後添加yAxis與chart.addaxis,我直接加載Yaxis圖表: ..... xAxis:[{type:'datetime', 標題:{ 文字: '日期' }}], Y軸:我在這裏的動態加載的AXIS, 系列:[] ..... 這工作,因爲我可以在一開始獲得軸.. otherway它不起作用。不管怎樣,謝謝你!對不起我的英語不好。 – Fabricio 2014-10-30 21:08:23