使用 "google.visualization.NumberFormat" 添加后缀

Add suffix using "google.visualization.NumberFormat"

一直在尝试在 Google 仪表图上的值旁边添加一个“%”,我确定我遗漏了一些愚蠢的东西。

这是我在另一个 post 之后尝试的方法:Adding a % sign to Google Gauges

google.charts.load('current', {
                    'packages': ['gauge']
                });
                google.charts.setOnLoadCallback(drawChart);

                function drawChart() {

                    var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1Z-eKZJ_XbmnoLYyG4cht40KMo07_CYnLP-hPi1ZBjnw/edit#gid=0');
                    query.send(handleQueryResponse);

                    var options = {
                        redFrom: 0,
                        redTo: 35,
                        yellowFrom: 35,
                        yellowTo: 65,
                        greenFrom: 65,
                        greenTo: 100,
                        minorTicks: 5
                    };
                   var formatter = new google.visualization.NumberFormat( {suffix: '%'} ); formatter.format(data,1);
function handleQueryResponse(response) {
                        var data = response.getDataTable();
                        new google.visualization.Gauge(document.getElementById('gaugechart')).draw(data);
                    }
                }

任何朝着正确方向的推动将不胜感激,请保持温和...

仅供参考,这是我在 Stack Exchange 中的第一个 post,任何格式错误或问题请告诉我。

需要等数据返回后再尝试使用formatter
将其移入 handleQueryResponse

google.charts.load('current', {
  callback: function () {
    var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1Z-eKZJ_XbmnoLYyG4cht40KMo07_CYnLP-hPi1ZBjnw/edit#gid=0');
    query.send(handleQueryResponse);

    function handleQueryResponse(response) {
      var data = response.getDataTable();

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

      var options = {
        redFrom: 0,
        redTo: 35,
        yellowFrom: 35,
        yellowTo: 65,
        greenFrom: 65,
        greenTo: 100,
        minorTicks: 5
      };

      new google.visualization.Gauge(document.getElementById('gaugechart')).draw(data, options);
    }
  },
  packages: ['gauge']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="gaugechart"></div>