在Google Charts y轴上将时间格式设置为小时:分钟
我有一个Google图表,其中y轴以分钟为单位。
I have a Google Chart where the y-axis is measured in minutes.
如何格式化y轴,使标签以格式显示时间例如 2hrs40
或 2:40
类似?我不想以原始分钟显示时间,我不想在90分钟内显示为1.5的小数。
How can I format the y-axis so the labels display the time in a format like 2hrs40
, or 2:40
, or something similar? I don't want to display the time in raw minutes, and I don't want to display it as a decimal like "1.5" for 90 minutes.
a href =https://developers.google.com/chart/interactive/docs/gallery/barchart =nofollow>文档告诉我使用 ICU模式集,但我无法从该页面计算出来。
The documentation tells me to use the ICU Pattern Set, but I can't figure it out from that page.
这是可能吗?如果我不能直接格式化这样的时间,是否有一种方式我可以通过改变< svg>
元素后 ?
Is this possible? And if I can't format the time like this directly, is there a way I can "hack" the chart after the fact by changing the <svg>
element using Javascript?
格式化选项不允许这样做。但是,您可以使用 vAxis.ticks
选项手动指定要用于刻度线的值以及要用于表示值的字符串。 vAxis.ticks
选项采用对象数组,其中每个对象具有 v
(value)和 f
(格式化的值 - 图表上显示的内容)属性。这样的东西应该工作:
The formatting options don't allow you to do that. You can, however, use the vAxis.ticks
option to manually specify the values to use for the tick marks and the strings you want to use to represent the values. The vAxis.ticks
option takes an array of objects, where each object has v
(value) and f
(formatted value - what gets displayed on the chart) properties. Something like this should work:
vAxis: {
ticks: [{v: 0, f: '0:00'}, {v: 30, f: '0:30'}, {v: 60, f: '1:00'}, {v: 90, f: '1:30'}]
}