想要在Google饼图的图例中显示百分比数据 [英] Want to show percentage data in legends of google pie chart

查看:115
本文介绍了想要在Google饼图的图例中显示百分比数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的代码中使用的是Google Charts API特别是饼图,我想显示在图表内也显示图例的百分比

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

如何在图例中显示29.2%的睡眠?

How can i display 29.2% sleep in legend?

推荐答案

您可以通过两种方式执行此操作;要么在DataTable中设置标签的格式化值以包含百分比,例如:

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) + '%)');

,或者您可以将legend.position选项设置为"labeled",这将更改图例的绘制方式,但会将百分数添加到标签中:

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'
}

在此处查看示例: http://jsfiddle.net/asgallant/Su6TX/

这篇关于想要在Google饼图的图例中显示百分比数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆