我试图在金额旁边得到"$"。应如下所示:"$0.005" 怎么做?
附言。prefix: '$'
不起作用。
<script>
google.charts.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country', 'Spent', 'Clicks'],
['US', 0.005, 1],
]);
var options = {
colorAxis: {
colors: ['grey','#444']
},
prefix: '$'
};
var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));
chart.draw(data, options);
}
</script>
您可以使用对象表示法来提供值(v
(和格式化值(f
(...
{v: 0.005, f: '$0.005'}
请参阅以下工作片段...
google.charts.load('current', {
packages: ['geochart']
}).then(function () {
var data = google.visualization.arrayToDataTable([
['Country', 'Spent', 'Clicks'],
['US', {v: 0.005, f: '$0.005'}, 1],
]);
var options = {
colorAxis: {
colors: ['grey','#444']
},
};
var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));
chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="regions_div"></div>
或者使用数字格式化程序来格式化数据表(其操作与上述相同(...
var formatTooltip = new google.visualization.NumberFormat({
pattern: '$#,##0.000'
});
formatTooltip.format(data, 1);
请参阅以下工作片段...
google.charts.load('current', {
packages: ['geochart']
}).then(function () {
var data = google.visualization.arrayToDataTable([
['Country', 'Spent', 'Clicks'],
['US', 0.005, 1],
]);
var options = {
colorAxis: {
colors: ['grey','#444']
},
};
var formatTooltip = new google.visualization.NumberFormat({
pattern: '$#,##0.000'
});
formatTooltip.format(data, 1);
var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));
chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="regions_div"></div>