如何在Google图表中格式化#的格式以使用逗号 [英] How to format #'s in Google Charts to have commas

查看:45
本文介绍了如何在Google图表中格式化#的格式以使用逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Visualization API,又名 Google图表,并且我试图得到要显示的数字,在其中.

I'm using the Google Visualization API, aka Google Charts, and I'm trying to get the numbers to show ,'s in them.

我的数据:

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 ,但是它需要数字.谢谢.

On the pie chart, if you hover over the slices, it shows 1456632 for the Mobile slice. Can I have it show 1,456,632 ? I've tried passing in strings and not numbers in the arrayToDataTable to define my data, but it needs numbers. Thanks.

推荐答案

您需要使用google formatter:

You need to use google formatter:

var formatter = new google.visualization.NumberFormat(
  {negativeColor: 'red', negativeParens: true, groupingSymbol:','});
formatter.format(data, 1);      

详细了解 NumberFormatter

这篇关于如何在Google图表中格式化#的格式以使用逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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