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

Luke Shaheen picture Luke Shaheen · May 2, 2012 · Viewed 17.1k times · Source

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?

Answer

Okan Kocyigit picture Okan Kocyigit · May 2, 2012

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
                 });
}
​