将时间格式化为小时:Google 图表 y 轴上的分钟 [英] Format a time as hours:minutes on a Google Charts y-axis

查看:33
本文介绍了将时间格式化为小时:Google 图表 y 轴上的分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Google 图表,其中 y 轴以分钟为单位.

I have a Google Chart where the y-axis is measured in minutes.

如何格式化 y 轴,以便标签以 2hrs402: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.

文档 告诉我使用 ICU 模式集,但我无法从该页面弄清楚.

The documentation tells me to use the ICU Pattern Set, but I can't figure it out from that page.

这可能吗?如果我不能像这样直接格式化时间,有没有办法事后通过使用 Javascript 更改 <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(值)和 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'}]
}

这篇关于将时间格式化为小时:Google 图表 y 轴上的分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆