我正在尝试更改Google测量仪上轴的数字格式。默认情况下,轴值是一个整数(例如0,120),但我想显示一个£符号和格式作为货币(例如£0,£120)。我已经能够使用NumberFormat更改仪表底部显示的值的格式,但不能应用于仪表的其余部分。
基本仪表的代码如下:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['gauge']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data1 = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Spend', 80],
]);
var options1 = {
width: 500, height: 300
};
// change number format to £
var formatter = new google.visualization.NumberFormat(
{pattern: '£###,###'});
formatter.format(data1, 1);
var chart = new google.visualization.Gauge(document.getElementById('chart_div1'));
chart.draw(data1, options1);
}
</script>
</head>
<body>
<div id="chart_div1"></div>
</body>
</html>
如何在仪表外部的数字上添加£符号?谢谢。
答案 0 :(得分:1)
您可以为majorTicks
提供一系列字符串,以指定您自己的...
google.charts.load('current', {'packages':['gauge']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data1 = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Spend', 80],
]);
var options1 = {
width: 500, height: 300,
majorTicks: [
'£0', '', '', '', '£100'
]
};
// change number format to £
var formatter = new google.visualization.NumberFormat({
pattern: '£###,###'
});
formatter.format(data1, 1);
var chart = new google.visualization.Gauge(document.getElementById('chart_div1'));
chart.draw(data1, options1);
}
&#13;
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div1"></div>
&#13;