1

我正在使用Google Chart API創建多行圖表,我想使用2個Y軸,例如 - >enter image description here,但一個軸設置爲最大24000我的6個國家,第二個爲「全球全球」專欄的90000。Google可視化API雙Y軸 - 無法調整目標AxisIndex

的問題是,我的組選項從不返回「總世界上第二Y軸和其他6個國家中第一個Y軸,無論我怎麼安排選項「targetAxisIndex」:

var tot = 95000; 
var min = 0, var max = 24000; 
.... 

var options = { 
      title: 'Top Consuming Nations - Thousand barrels daily', 

      hAxis: {title: 'Year'}, 
      width: 1050, height : 400, 

      vAxes: [ 
       {title: 'Top Countries', titleTextStyle: {color: '#FF0000'}, maxValue: max}, // Left axis maxValue: 60000 
       {title: 'Total World', titleTextStyle: {color: '#FF0000'}, maxValue: tot} // Right 
      ], 
      series:[ 
       {targetAxisIndex:1}, 
       {targetAxisIndex:0} 
      ], 
      legend: { position: 'top', alignment: 'start' } 
      }; 

這裏是完整的代碼:http://plnkr.co/edit/u5xXExdkTTYU8fHxWzHB?p=preview

回答

1

我發現在谷歌論壇的答案:

克里斯 - 嗨,

該系列選項應該是系列索引到系列選項的映射。當你將它指定爲一個數組時,你基本上是在隱式地做這個賦值。所以在你的例子中,系列0將在軸1上,系列1將軸上。所有其他系列將轉至默認軸(0)。你的問題可以很容易地解決,只需重組你的系列,使總數是第一。或者,您可以明確指定系列6(您的總系列,'country6')應該在軸1上進行。默認情況下,軸0上的內容將進入,因此不需要明確指定。下面是與解決方案的第二版本的plunkr的更新版本(因爲這是更容易爲我做的):http://plnkr.co/edit/GhsNcBCtDW0i4OTu0VJR?p=preview

var options = { 
      title: 'Top Consuming Nations - Thousand barrels daily', 

      hAxis: {title: 'Year'}, 
      width: 1050, height : 400, 

      vAxes: [ 
       {title: 'Top Countries', titleTextStyle: {color: '#FF0000'}, maxValue: max}, // Left axis maxValue: 60000 
       {title: 'Total World', titleTextStyle: {color: '#FF0000'}, maxValue: tot} // Right 
      ], 
      series:{ 
       6: {targetAxisIndex: 1} 
      }, 
      legend: { position: 'top', alignment: 'start' } 
      }; 

      var chart = new google.visualization.LineChart(document.getElementById(chartDiv)); 

      chart.draw(data, options);