我正在使用 Google Charts API 创建学生考试成绩的图表。图表的 X 轴显示一周中的几天。 Y 轴上的图表显示了学生参加考试的时间。 (目的是让老师看看学生是否加快速度)。但是,我有一个问题:
我的数据采用 timeofday 格式,并且我使用 Google Charts [HH,MM,SS,MSEC] 格式向图表提供值作为持续时间。当图表呈现时,Y 轴打印为“HH:MM:SS”。我真的很想定制它,因为秒数几乎没有用,而且看起来比我想要的更混乱。
图表 API 表示您可以为列指定“模式”,我已指定“HH:MM”。然而,这似乎根本没有生效。有人有在 Google Charts 中格式化时间的经验并且知道如何做到这一点吗?
I'm working with the Google Charts API to create a graph of a student's test-taking performance. On the X axis, the graph shows the days of the week. On the Y axis, the graph shows how long the student spent taking the exam. (The goal is for teachers to see if the student speeds up). However, I have a problem:
My data is in the timeofday format, and I'm providing values to the chart as time durations using the Google Charts [HH,MM,SS,MSEC] format. When the chart renders, the Y axis is printed as "HH:MM:SS". I'd really like to customize that because the seconds are pretty useless and it looks messier than I'd like.
The Charts API says you can specify a "pattern" for a column, and I've specified "HH:MM". However, that doesn't seem to take effect at all. Anybody have experience formatting timeofday in Google Charts and know how to do this?
发布评论
评论(4)
该格式深藏在 API 文档中。 (http://code.google.com/apis/chart/interactive/docs/reference.html)。它大约下降了四分之一,它说:
The format is buried deep in the API documentation. (http://code.google.com/apis/chart/interactive/docs/reference.html). It is about quarter way down, it says:
一言以蔽之:以下网址是当天股票价格的完整工作版本,可以在“http://www.harmfrielink.nl/Playgarden/GoogleCharts-Tut-07.html'
由于无法正确发布完整的列表,因此我只给出重要部分:
该示例将:
我希望这个例子能够清楚地说明如何以正确的方式处理数据。
More than words can say: The followingURL is a full working version for Stockprices during the days, and can be found at 'http://www.harmfrielink.nl/Playgarden/GoogleCharts-Tut-07.html'
Since a complete listing can not be posted correctly I only give the important parts:
The example will:
I hope this example makes it clear how to handle the data in a correct way.
在图表选项对象中,您可以使用字段 format 设置 vAxis 对象,并提供一个包含您要使用的模式的字符串,这里是一个示例:
查看 vAxis 对象。
对于字符串格式,您应该查看 http://userguide.icu-project.org/formatparse/datetime 为您构建您喜欢的模式。
In chart the options object you could set the vAxis object with the field format and provide a string with the pattern you want to use here's an example:
Look at the vAxis object.
For the string format you should look to http://userguide.icu-project.org/formatparse/datetime to build you the pattern you prefer.
您可以使用 hAxis.format 或 vAxis.format 选项。这允许您指定一个格式字符串,您可以在其中使用占位符字母来表示一天中的不同部分
要摆脱秒,您可以设置 Y 轴的格式,如下所示:
You can use the hAxis.format or vAxis.format option. This allows you to specify a format string, where you use placeholder letters for different parts of your timeofday
To get rid of the seconds, you can set the format of the Y Axis like this: