写谷歌图表API的定制格式 [英] Write a custom formatter for Google Charts Api

查看:138
本文介绍了写谷歌图表API的定制格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个图表上一个10K的运行,以显示我的时间。一切工作,因为它应该是我唯一的问题是,我想格式化时间的显示方式。

I want to create a chart to display my time over a 10k run. Everything is working as it should, the only problem that I have is, that I want to format how the time is displayed.

目前的时间显示为一个数字而重新presents秒。例如一个30分钟的运行归结至10800秒。谷歌提供的格式化确实涉及了很多东西,但我不是他们所提供的真正的快乐。

Currently the time is displayed as a number which represents the seconds. For example a 30 minute run comes down to 10800 seconds. The formatters provided by google do cover a lot of stuff, but I'm not really happy with what they provide.

<一个href=\"http://$c$c.google.com/apis/chart/interactive/docs/reference.html#formatters\">http://$c$c.google.com/apis/chart/interactive/docs/reference.html#formatters

不幸的是对于如何实现自己的格式化的信息。是否有任何机会,我可以延长格式化或者是有一个需要实现的接口?

Sadly there is no information on how to implement your own formatter. Is there any chance I can extend a formatter or is there an interface that needs to be implemented?

我会做的第一件事会做解析数10800一个不错的时间好像是30:00.00(30分0秒,0 millisecons)。
也许这已经是可能与patternformatter,但我看不出,因为有参与计算,不知道如何在patternformatter实现这一点。

The first thing I would do would do parse the number 10800 to a nice time like 30:00.00 (30 minutes, 0 seconds, 0 millisecons). Maybe this is already possible with a patternformatter, but i don't see how, as there is calculating involved and don't know how to implement this in the patternformatter.

感谢您的帮助。
约翰尼

Thank you for your help. Johnny

推荐答案

使用的日期格式一个自定义模式。例如:

Use a DateFormat with a custom pattern. E.g.:

google.visualization.DateFormat({pattern: "mm:ss.SSS"});

需要注意的是,这显示时间的日一个JS Date对象,所以你需要提供运行时间为JS日期。因此,无论指明在你的数据进行采样的实际时间的日。或者,如果你想只显示你自运行开始的相对时间,你可以做这样的事情:

The caveat is that this displays the time-of-day of a JS Date object, so you'll need to provide your run times as JS dates. So either specify the actual time-of-day at which your data was sampled. Or, if you want to just show the relative time since the start of your run, you could do something like this:

new Date(new Date('Jan 01 2000').getTime() + sampleTime)

...其中sampleTime是以毫秒为单位的每个采样点的时间。 (这只是设置的时间自午夜01/01/2000毫秒,所以时/分/秒将反映您的运行时)

... where sampleTime is the time of each sample point in milliseconds. (This just sets the time as milliseconds since midnight 01/01/2000, so the hour/minute/second will reflect your run time)

这篇关于写谷歌图表API的定制格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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