我正在使用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
,但它需要数字。谢谢。
您需要使用Google Formatter:
var formatter = new google.visualization.NumberFormat(
{negativeColor: 'red', negativeParens: true, groupingSymbol:','});
formatter.format(data, 1);
阅读有关NumberFormatter的更多信息
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句