给定饼图的数据:
data = new google.visualization.arrayToDataTable([
['Sales', 'Revenue Distribution'],
['Author', 5],
['Company', 2],
['Tax', 0.4],
['Payment Processors', 0.9]
]);
drawChart();
如何使它显示为美元金额?无论是在工具提示中还是在实际图表本身上(两者都更可取!)
例如,理想情况下这会起作用:
data = new google.visualization.arrayToDataTable([
['Sales', 'Revenue Distribution'],
['Author', '$5'],
['Company', '$2'],
['Tax', '$0.4'],
['Payment Processors', '$0.9']
]);
drawChart();
最佳答案
这是可能的,它将应用于切片和工具提示。您需要包含的是 number formatter .
关键是在“创建”图表之前应用以下内容。
var formatter = new google.visualization.NumberFormat({
prefix: '$'
});
formatter.format(data, 1);
var options = {
pieSliceText: 'value'
};
这首先创建格式化程序并将其应用于数据,然后下一个选项强制饼图显示格式化值,而不是计算的百分比。你可以看到它在 this jsfiddle 中工作。 .
受到此处答案的启发和改编:Formatting google charts programmatically
关于javascript - 谷歌图表显示金钱而不是百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10688225/