Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display item in legend even if value = 0 with Google Charts Tools Pie Chart

I'm using Google Charts Tools, specifically the Pie Chart.

Naturally, if a item has a value of 0, it is not displayed in the pie (since it occupies 0% of the pie). However, it doesn't display in the legend either.

How can I manipulate the initialization options to still show a 0 value item in the legend, so that users can see that the item exists, it just has a 0 value?

like image 501
Luke Shaheen Avatar asked May 02 '12 21:05

Luke Shaheen


People also ask

How do you show no data available on Google Chart?

Use noData() method to enable "No data" label: chart. noData().

How do you show a value in a Google pie chart?

How to display both Percentage and Values in Google Pie Chart ? You can't display both on the slice labels, but if you set the pieSliceText option to 'label' and the legend. position option to 'labeled' , you will see the value on the slice and the percent on the legend label.


1 Answers

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                  }); } ​ 
like image 138
Okan Kocyigit Avatar answered Sep 21 '22 06:09

Okan Kocyigit