2012-05-02 128 views

回答

48

設置sliceVisibilityThreshold爲零將解決您的問題。

function drawVisualization() { 
    // Create and populate the data table. 
    var data = google.visualization.arrayToDataTable([ 
    ['Task', 'Hours per Day'], 
    ['Work', 11], 
    ['Eat', 0], 
    ['Commute', 2], 
    ['Watch TV', 2], 
    ['Sleep', 7] 
    ]); 

    // Create and draw the visualization. 
    new google.visualization.PieChart(document.getElementById('visualization')). 
     draw(data, {title:"So, how was your day?", 
       sliceVisibilityThreshold:0 
       }); 
} 
​ 
+2

正是我一直在尋找的 - 只是無法理解的API中的描述!謝謝! –

+1

設置sliceVisibilityThreshold = 0有助於在至少有一個圖表數據字段具有非零數字但傳說不顯示的情況下,所有字段均爲零。我們如何在這種情況下展示傳奇? –

+0

非常感謝... –

0

我最近添加了谷歌圖表,並面臨着它的問題,爲它添加零值。
感謝@ocanal,我用sliceVisibilityThreshold:0,但以其他方式。

<script type="text/javascript"> 
     google.charts.load('current', {'packages':['corechart']}); 
     google.charts.setOnLoadCallback(drawChart); 

     function drawChart() { 

     var data = google.visualization.arrayToDataTable([ 
      ['Task', 'Hours per Day'], 
      ['B-TRIPS',  <?php echo $arr_get_a_org['total_trips']; ?>], 
      ['Reimbursed',  <?php echo $arr_get_a_org['reimbursed_trips']; ?>], 
      ['Approved', <?php echo $arr_get_a_org['approved_trips']; ?>], 
      ['Pending', <?php echo $arr_get_a_org['pending_trips']; ?>] 
     // ['Sleep', <?php echo $arr_get_a_org['total_trips']; ?>] 
     ]); 

     var options = { 
      title: 'OVERVIEW', 
      backgroundColor:'#e2e1e0', 
      pieSliceText:'value', 
      sliceVisibilityThreshold :0 

     }; 

     var chart = new google.visualization.PieChart(document.getElementById('piechart')); 

     chart.draw(data, options); 
     } 
</script> 

作爲選項定義的方式已經改變,更多信息請查看Google Chart site

相關問題