2013-07-24 47 views
1

我想顯示一個圖表與2軸Y軸,但我總是得到一個圖表與1 Y軸。我正在閱讀不同的解決方案,但沒有工作......我認爲問題是我有一個JSON數據表。這個數據的格式是:多個Y軸谷歌與Json數據圖表

{"cols":[{"label":null,"type":"number"},{"label":"I rated max","type":"number"},{"label":"Rdc max","type":"number"}],"rows":[{"c":[{"v":1},{"v":0.5},{"v":0.32}]},{"c":[{"v":1.5},{"v":0.63},{"v":0.76}]},... 

我試着用vAxes選項,但它沒有工作......一些想法?

謝謝!

編輯:我完整的代碼是這樣的:

// Load the Visualization API and the piechart package. 
    google.load('visualization', '1', {'packages':['corechart']}); 

    // Set a callback to run when the Google Visualization API is loaded. 
    google.setOnLoadCallback(drawChart); 

    function drawChart() { 

     // Create our data table out of JSON data loaded from server. 
     var data = new google.visualization.DataTable(<?=$jsonTable?>); 
     var options = { 
       title: 'I/R-L chart', 
       hAxis: {title: 'L value [µH]', titleTextStyle: {color: 'red'} }, 
       //vAxis: { 
       // title: "I rated max/ Rdc max", 

       // maxValue:1.5 


       //}, 
       vAxes: { 0: {logScale: false}, 1: {logScale: false}}, 

       series:{ 

        0:{targetAxisIndex:0}, 

        1:{targetAxisIndex:0}}, 


      pointSize:8 
     } 

     // Instantiate and draw our chart, passing in some options. 
     // Do not forget to check your div ID 
     var chart = new google.visualization.ScatterChart(document.getElementById('chart_div')); 
     chart.draw(data, options); 
    } 
+0

這是不太可能的數據表是你的問題。我需要看到你的整個圖表代碼,以幫助你弄清楚這一點。 – asgallant

+0

我編輯了我的帖子並添加了代碼。我嘗試使用vAxes但不起作用,它只顯示一個軸(左側) – Mastor

回答

1

的問題是雙重的:

1)ScatterCharts不支持多個垂直軸。根據數據的結構(如果上面的示例DataTable代表了數據,那麼您的數據結構就很好),那麼可以使用LineChart來模擬ScatterChart。您只需要將「lineWidth」選項設置爲0. 2)您需要爲每個軸分配至少一個數據系列,否則右側的vAxis將不會繪製。

試試這個:

// Load the Visualization API and the piechart package. 
google.load('visualization', '1', {'packages':['corechart']}); 

// Set a callback to run when the Google Visualization API is loaded. 
google.setOnLoadCallback(drawChart); 

function drawChart() { 
    // Create our data table out of JSON data loaded from server. 
    var data = new google.visualization.DataTable(<?=$jsonTable?>); 
    var options = { 
     title: 'I/R-L chart', 
     hAxis: {title: 'L value [µH]', titleTextStyle: {color: 'red'} }, 
     vAxes: { 0: {logScale: false}, 1: {logScale: false}}, 
     series:{ 
      0:{targetAxisIndex:0}, 
      1:{targetAxisIndex:1} 
     }, 
     pointSize:8, 
     lineWidth: 0 
    } 

    // Instantiate and draw our chart, passing in some options. 
    // Do not forget to check your div ID 
    var chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
    chart.draw(data, options); 
} 
+0

非常感謝您的答覆。直到星期一我都無法嘗試,但聽起來不錯! :D當我嘗試我會評論和標記爲正確的答案 – Mastor

+0

它的作品完美!非常感謝你 – Mastor