2013-04-05 13 views
5

Voglio mostrare un rapporto con grafici di google, usando le percentuali. Io so come cambiare il vAxis a percentuali:mostra percentuali google charts su tooltip

vAxis: {format:'#%'}, 

ma il problema è la mia tecnica non è indicata in percentuale sui tooltip, ma in valori decimali (0,85 invece del previsto 85%)

enter image description here

Il mio codice è qui sotto:

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 ]]) 

risposta

13

è possibile utilizzare formatters.

Ecco un esempio (bastone questo al tuo codice prima di disegnare il grafico):

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

I formati si possono usare sono un sottoinsieme della ICU DecimalFormat se si desidera cambiare leggermente il formato da quello che ho dare sopra.