[英]show percentages google charts on tooltip
我想用百分比显示谷歌图表的比例。 我知道如何将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 ]])
您可以使用格式化程序 。
这是一个例子(在绘制图表之前将其粘贴到您的代码中):
var formatter = new google.visualization.NumberFormat({pattern:'#,###%'});
formatter.format(data, 1);
formatter.format(data, 2);
如果您想稍微改变我上面给出的格式,您可以使用的格式是ICU DecimalFormat的子集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.