Display item in legend even if value = 0 with Google Charts Tools Pie Chart
setting sliceVisibilityThreshold
as zero will solve your problem.
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
});
}
I was recently adding the Google Charts and was facing problem in it, for Adding zero value in it.
Thanks for @ocanal, I used sliceVisibilityThreshold:0, but in some other way.
<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>
As the way of defining of options have changed, for more info check out Google Chart site