更改谷歌图表中Tooltip数据和Y轴的数字格式

Changing the number format in google charts graphs of the Tooltip Data and also Y Axis

本文关键字:格式 数字 数据 Tooltip 谷歌      更新时间:2023-09-26

我需要在工具提示数据(Y轴)和Y轴中的每千个后面添加一个逗号。如何更改数字格式?我试着在代码中添加它,但似乎不起作用。我的vAxis和hAxis标题显示也不起作用。

var options = {
  title:'<?php echo $row["$graph_title"];?>',
  height: 'auto',
  width : 'auto',
  tooltip : {trigger: 'selection'},
  is3D: true,
  vAxis: {title: '<?php echo $row1["$y_axis"]; ?>'},
  hAxis: {title: '<?php echo $row1["$x_axis"]; ?>'},
  bar: {groupWidth: "70%"},
  vAxis: {format:'decimal'}
};

您可以使用numberFormat。文件将其描述为

描述应如何格式化数字列。格式选项包括指定前缀符号(如美元符号)或用作千标记的标点符号。

var numberFormat = new google.visualization.NumberFormat({
    groupingSymbol: ','
});
numberFormat.format(data, COLUMNNUMBER);