我正在使用 Google Visualization API(又名 Google Charts),并且我正在尝试获取其中显示的数字。
我的数据:
var data = google.visualization.arrayToDataTable([
['Device', 'Views'],
['Mobile', 1456632],
['Tablet', 6]
]);
图表初始化:
var myChart = new google.visualization.PieChart(document.getElementById('myChart'));
myChart.draw(data, { title: 'My pie chart' });
在饼图上,如果将鼠标悬停在切片上,则会显示移动切片的 1456632
。我可以让它显示 1,456,632
吗?我尝试在 arrayToDataTable
中传递字符串而不是数字来定义我的data
,但它需要数字。谢谢。
最佳答案
您需要使用谷歌格式化程序:
var formatter = new google.visualization.NumberFormat(
{negativeColor: 'red', negativeParens: true, groupingSymbol:','});
formatter.format(data, 1);
了解更多关于NumberFormatter的信息
关于google-visualization - 如何在 Google 图表中将 # 格式化为逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25687354/