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>