2014-01-25 116 views
0

我想要使用GOOGLE圖表繪製組合圖,其中我的銷售位於左側y軸,薪金位於右側y軸(輔助軸)上,如線圖所示。 但是,我的代碼沒有運行。無法找出問題所在。 請幫忙。 片段代碼:在右側添加輔助軸

<script type="text/javascript" src="//www.google.com/jsapi"></script> 
<script type="text/javascript"> 
    google.load('visualization', '1', {packages: ['corechart']}); 
</script> 
<script type="text/javascript"> 
    function drawVisualization() { 
    // Create and populate the data table. 
    var data = google.visualization.arrayToDataTable([ 
     ['Employee ID', 'Sales', 'Salary'], 
     ['7000234', 560024, 9765], 
     ['7000260', 1180800, 15621], 
     ['7000262', 244308, 9212], 
     ['7000273', 390912, 8650], 
     ['7000288', 870445, 6692] 
    ]); 

    // Create and draw the visualization. 
    var ac = new google.visualization.ComboChart(document.getElementById('visualization')); 
    ac.draw(data, { 
     title : 'Sales and Salary', 
     width: 800, 
     height: 400, 
     hAxis: {title: "Employee ID"}, 
     vAxes: [ 0: {title: "Sales"}, 1: {title:"Salary"}], 
     series: { 
       0:{ type: "bars", targetAxisIndex: 0 }, 
       1: { type: "line", targetAxisIndex: 1} 
      }, 
    }); 
    } 


    google.setOnLoadCallback(drawVisualization); 
</script> 

回答

2

看來唯一的錯誤是在選項vAxes。應該使用{...}代替[...]。你必須改變:

vAxes: [ 0: {title: "Sales"}, 1: {title:"Salary"}], 

vAxes: { 0: {title: "Sales"}, 1: {title:"Salary"}}, 

example at jsbin

+0

感謝。有效! :d – user1855888