Format time in google gauge chart

a 夏天 提交于 2019-12-11 06:34:50

问题


Is there anyway to format Google Gauge chart from seconds to time like this?


回答1:


using object notation, you can provide a value (v:) and a formatted value (f:)

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

the gauge chart will display the formatted value

see following working snippet...

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>


来源:https://stackoverflow.com/questions/40720570/format-time-in-google-gauge-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!