Google Chart - Add percentage to PieChart

https://stackoverflow.com/questions/19178029/want-to-show-percentage-data-in-legends-of-google-pie-chart


8down voteaccepted
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'
}

Comments

Popular posts from this blog

How to create an organizational chart in your webpage using Google Organization Chart Tools

Embed JSX code with if condition in React app