I am using google charts API specifically pie chart in my code i want to show percentage which is displayed inside chart to the legends also
How can i display 29.2% sleep in legend?
You can do this two ways; either set the formatted values of the labels in the DataTable to include the percents, eg:
// assume sleep is row 4, "sleepPercent" is the percent for sleep
data.setFormattedValue(4, 0, data.getValue(4, 0) + ' (' + (sleepPercent * 100).toFixed(1) + '%)');
or you can set the legend.position
option to "labeled", which changes the way the legend is drawn, but adds the percents to the labels:
legend: {
position: 'labeled'
}
see an example here: http://jsfiddle.net/asgallant/Su6TX/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With