24 hour time format for continuous date format x-axis line chart

2,893 views
Skip to first unread message

John Beranek - PA

unread,
Sep 24, 2014, 1:35:57 PM9/24/14
to google-visua...@googlegroups.com
I'm using a line chart to chart some data with a continuous date format x-axis.

Previously I was only plotting a single data point per day, and everything was fine, but I recently changed the chart so I get a point per hour.

However, I'm unhappy with the 12-hour time format that the chart is showing:


I tried the following options code, but it has no effect - thinking about it, I wouldn't really want the format to be so rigid, because as the screenshot shows, the x-axis labels are more clever than a fixed date/time format...

 hAxis: { format: 'yyyy/MM/dd HH:mm'},

So, is it possible to change the x-axis time format to 24-hour?

Cheers,

John

Daniel LaLiberte

unread,
Sep 24, 2014, 2:25:47 PM9/24/14
to google-visua...@googlegroups.com
John,

We actually do have more formatting options for the date and time axes, but they are, as of yet, undocumented.   We should probably make the format option work as you guessed as well, at least as a fallback.

Here is a sneak peak of how to use the new format options to do what I believe you want:

   "hAxis": {
      "gridlines": {
        "count": "-1",
        "units": {
          "minutes": {
            "format": [
              "HH:mm"
            ]
          },
          "hours": {
            "format": [
              "MM/dd HH",
              "HH"
            ]
          },
          "days": {
            "format": [
              "yyyy/MM/dd"
            ]
          }
     }}}

There are similar options under minorGridlines as well, to control the format of the minor ticks.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

John Beranek - PA

unread,
Sep 24, 2014, 2:32:18 PM9/24/14
to google-visua...@googlegroups.com
[Unusually for me I'm top-posting, not sure on Google Groups etiquette... ;)]

Thanks for the quick reply.

So, the different option sets are for the different date/time resolutions, yes?

I'll have a play and see what I like the best. I think I may stick with the short English month names.

Cheers,

John

Daniel LaLiberte

unread,
Sep 24, 2014, 2:38:19 PM9/24/14
to google-visua...@googlegroups.com
Yes, each set (e.g. "minutes", "hours") is for the different resolutions of the value.  Look for the smallest non-zero part of the value to decide which resolution applies.  So "hours" applies to 3pm but "minutes" applies to 3:15pm.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

John Beranek - PA

unread,
Sep 24, 2014, 2:50:17 PM9/24/14
to google-visua...@googlegroups.com
Not getting those options to have any effect...is there a minimum version of the visualization API to load?

Cheers,

John
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

Daniel LaLiberte

unread,
Sep 24, 2014, 3:06:20 PM9/24/14
to google-visua...@googlegroups.com
I believe these options should be available now just by loading "1.0".  You could try "1.1" but it shouldn't make a difference for you.  If you can point me at page that shows your chart, I can take a look.

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

John Beranek - PA

unread,
Sep 24, 2014, 3:55:30 PM9/24/14
to google-visua...@googlegroups.com
Tricky as the page in on an intranet, and uses an Ajax data source...I'll see if I can quickly boil it down...

John
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

John Beranek - PA

unread,
Sep 24, 2014, 3:56:30 PM9/24/14
to google-visua...@googlegroups.com
Ah, changing it 1.1 did indeed do the trick though.

John

On Wednesday, 24 September 2014 20:06:20 UTC+1, Daniel LaLiberte wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

John Beranek - PA

unread,
Sep 24, 2014, 4:00:46 PM9/24/14
to google-visua...@googlegroups.com
Or potentially I've not got the hang of the minor ticks yet...more experimentation required...

John

John Beranek - PA

unread,
Sep 24, 2014, 4:06:39 PM9/24/14
to google-visua...@googlegroups.com
Happiness is...an appropriate date format:

John

John Beranek - PA

unread,
Sep 24, 2014, 4:14:31 PM9/24/14
to google-visua...@googlegroups.com

Still confused by the case where you've got just a single date boundary though:

That's with:

        hAxis:
        {
          gridlines:
          {
            count: -1,
            units:
            {
              minutes:
              {
                format: [ "HH:mm" ]
              },
              hours:
              {
                format: [ "HH:mm" ]
              },
              days:
              {
                format: [ "dd MMM" ]
              }
            },
          },
          minorGridlines:
          {
            count: -1,
            units:
            {
              hours:
              {
                format: [ "HH:mm" ]
              },
              minutes:
              {
                format: [ "HH:mm" ]
              }
            }
          }
        },

John

John Beranek - PA

unread,
Sep 24, 2014, 4:17:39 PM9/24/14
to google-visua...@googlegroups.com
To clarify I was trying to get something like:

22:00  23:00 24 Sep 01:00 02:00

John

Daniel LaLiberte

unread,
Sep 24, 2014, 4:30:57 PM9/24/14
to google-visua...@googlegroups.com
Yes, this is a flaw in the current formatting mechanism, that it doesn't include a context value, such as the day and month at least once.  Making the format of this context value be customizable is part of the issue.  The best you can do now is, if you know what the context is, add it to your axis title.  

Glad you got it working, however.

The other option you can experiment with, by the way, is 'interval', which specifies the multiples of values that will be used.  For example, here is the default 'minutes' option for minorGridlines.units:

'minutes': {
    'format': [':mm'],
    'interval': [1, 2, 5, 15]
  }



To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

John Beranek - PA

unread,
Sep 24, 2014, 4:42:00 PM9/24/14
to google-visua...@googlegroups.com
Thanks again, I decided that reducing fontSize and using "dd/MM" allowed more minor ticks to be displayed, otherwise you can get peculiar things like:


So, I've gone with that.

John
Reply all
Reply to author
Forward
0 new messages