Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Charts Show Empty Items in Legend

When working with the pie chart in Google Charts it seems to ignore items with a value of zero. I would really like to get these items to show up in the legend even though their value is zero so that the users knows that it was a possible answer to the question. Is there a way to have a zero value item still show up in the legend?

like image 713
ctrlalt313373 Avatar asked Jan 06 '12 01:01

ctrlalt313373


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 I get rid of value data labels and legend?

On the Layout tab, in the Labels group, click Legend. Do one of the following: To hide the legend, click None. Tip: To quickly remove a legend or a legend entry from a chart, you can select it, and then press DELETE.

How do I get rid of the legend in my Google chart?

To hide the legend in Google Chart with JavaScript, we set the legend property to 'none' . const options = { //... legend: "none", }; to set legend to 'none' in the options object to hide the legend.


1 Answers

Setting the slice visibility threshold to 0 solved it for me. Notice the last option sliceVisibilityThreshold.

var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {
    title:'How Much Pizza I Ate Last Night',
    width:400,
    height:300,
    sliceVisibilityThreshold:0
});

(taken from the sample pie chart).

By default, the threshold is set to 1/720, which means (from the docs):

The slice relative part, below which a slice will not show individually. All slices that have not passed this threshold will be combined to a single slice, whose size is the sum of all their sizes. Default is not to show individually any slice which is smaller than half a degree.

like image 200
Michał Pałys-Dudek Avatar answered Nov 13 '22 15:11

Michał Pałys-Dudek