我想用百分比显示谷歌图表的比率。我知道如何将 vAxis 更改为百分比:
vAxis: {format:'#%'},
但问题是我的数据在工具提示中没有显示为百分比,而是以小数值显示(0.85 而不是预期的 85%)
我的代码如下:
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(function() {})
function drawChart(data) {
var data = google.visualization.arrayToDataTable(data);
var options = {
title: "Pourcentage de production et productivité de l'entreprise",
chartArea: {top:39},
vAxis: {format:'#%'},
pointSize:2
}
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
drawChart([['Year', '% de production', 'Productivité'],[ '06/03/2013', 0.85 , 0.58 ],[ '07/03/2013', 0.85 , 0.58 ],[ '23/03/2013', 0.85 , 0.58 ],[ '25/03/2013', 1 , 1.5 ],[ '26/03/2013', 0.72 , 0.63 ],[ '04/04/2013', 1 , 1.57 ]])
最佳答案
您可以使用 formatters .
这是一个示例(在绘制图表之前将其粘贴到您的代码中):
var formatter = new google.visualization.NumberFormat({pattern:'#,###%'});
formatter.format(data, 1);
formatter.format(data, 2);
您可以使用的格式是 ICU DecimalFormat 的子集如果您想稍微更改我上面给出的格式。
关于javascript - 在工具提示上显示百分比谷歌图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15830292/