Show google charts percent on tooltip

I want to show the ratio with google charts using percentages. I know how to change vAxis to percent:

vAxis: {format:'#%'},

but the problem is that my data is not displayed in percent on prompts, but in decimal values ​​(0.85 instead of the expected 85%)

enter image description here

My code is below:

  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 ]])
+5
source share
1 answer

You can use formatters .

Here is an example (link this to your code before drawing the chart):

  var formatter = new google.visualization.NumberFormat({pattern:'#,###%'});
  formatter.format(data, 1);
  formatter.format(data, 2);

The formats you can use are a subset of ICM DecimalFormat if you want to change the format a bit based on what I give above.

+13
source

All Articles