在google计量表中格式化时间

时间:2016-11-21 12:46:55

标签: api charts google-visualization gauge

有没有像这样不时地格式化Google Gauge图表? enter image description here

1 个答案:

答案 0 :(得分:2)

使用对象表示法,您可以提供值(v:)和格式化值(f:

{v: 4.2, f: '01:16:04'}

仪表图表将显示格式化值

请参阅以下工作代码段...

google.charts.load('current', {
  callback: function () {
    var data = google.visualization.arrayToDataTable([
      ['Label', 'Value'],
      [' ', {v: 4.2, f: '01:16:04'}]
    ]);

    var options = {
      height: 240,
      max: 5,
      minorTicks: 5,
      redFrom: 3.25,
      redTo: 5,
      yellowFrom: 1.65,
      yellowTo: 3.25,
      width: 240
    };

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