簡體   English   中英

在工具提示上顯示百分比谷歌圖表

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM