2013-11-27 62 views
0

我有這個谷歌餅圖在我的MVC應用程序,其中我需要移動到另一個控制器上點擊谷歌餅圖部分的下一個動作。在這裏是我的餡餅chhart和事件處理函數如何去谷歌餅圖的下一個動作onclick


<script> 
     function drawCharts() { 

       // Create the data table. 
       var dataP = google.visualization.arrayToDataTable([ 
        ['Risk Level', 'Number Of Patients'], 
        ['Low', @Model.RiskLevel[0]], 
        ['High', @Model.RiskLevel[1]], 
        ['Medium', @Model.RiskLevel[2]] 
       ]); 
var optionsP = { 
       is3D: true, 
       colors: ['#109618', '#DC3912', '#FF9900'], 
       title: 'Risk Level' 
      }; 
var chartP = new google.visualization.PieChart(document.getElementById('piechart_3d')); 
      google.visualization.events.addListener(chartP, 'select', selectHandler); 
      chartP.draw(dataP, optionsP); 
function selectHandler() { 
       var selectedItem = chartP.getSelection()[0]; 
       if (selectedItem) { 
        var topping = dataP.getValue(selectedItem.row, 0); 
        if (topping == "High") { 
         //go to action? 
        } 
       } 
      } 
</script> 

任何人可以幫助我嗎?

回答

0

我計算出來

var selectedItem = chartP.getSelection()[0]; 
       if (selectedItem) { 
        var topping = dataP.getValue(selectedItem.row, 0); 
        if (topping == "High") { 
         //go to action? 
         window.open("url to action", "_self", true) 
        } 
       } 
      } 
+1

不要使用'VAR將selectedItem = chartP.getSelection()[0];',如圖表可以有零選定的元素,這將導致該拋出異常。代之以:var selection = chartP.getSelection();'if(selection.length> 0){...}'。然後你可以在'if'語句中分配'selectedItem'。 – asgallant