google-visualization - 如何在 Google 图表中将 # 格式化为逗号

标签 google-visualization

我正在使用 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/

相关文章:

php - 使用示例数据但不使用自定义数据的 Google 图表

javascript - 无法更改 Google 图表工具的背景

javascript - 在 Google 可视化仪表板中使用类别过滤器控制列

javascript - 从 Javascript 中的 PHP 数组填充 Google GeoChart map 的问题

javascript - 谷歌图表仅在点击检查元素后显示

javascript - 谷歌图表注释未显示

javascript - 将链接插入 Google Charts api 数据?

php - 使用 google 图表、mysql 和 php 创建动态图表

javascript - Google 图表输入数据大小限制

google-visualization - Google Geochart(所有国家/地区)