gpt4 book ai didi

javascript - 谷歌图表 : How to get the percentage values of every slice in a pie chart?

转载 作者:行者123 更新时间:2023-12-02 16:58:09 25 4
gpt4 key购买 nike

我想获取每个切片的百分比值,目前我可以获得所选标签的名称,但我想获取每个标签的百分比值。我找不到方法来做到这一点,这可能吗?

http://jsfiddle.net/oaobxych/4/

function selectHandler() {
var selectedItem = chart.getSelection()[0];
if (selectedItem) {
var version = data.getValue(selectedItem.row, 0);
alert('The user selected ' + version);
}
}

最佳答案

也许你需要计算一下。

    var total = 0;
for (var f = 0; f < data.getNumberOfRows(); f++){
total += data.getValue(f, 1);
}
var selectedItem = chart.getSelection()[0];
if (selectedItem) {
var percentage = (data.getValue(selectedItem.row,1)*100/total).toFixed(1);
var version = data.getValue(selectedItem.row, 0);
alert('The user selected ' + version + ' a ' + percentage + '% of total');
}
}

http://jsfiddle.net/oaobxych/7/

关于javascript - 谷歌图表 : How to get the percentage values of every slice in a pie chart?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25999567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com