Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chart API: how can I change the format of dates on an axis?

I have a google chart (set up using chartkick And I am trying to make the dates appear shorter on the chart. My Data set looks something like this:

{"03/01/13" : 3, "03/02/13" : 0, "03/03/13" : 10 }  //etc.

However, when I load up the chart the date is formatted like so: Mar 1, 2013. How can I get the date to appear as I passed it, or in some other short format? The longer fields looked very cramped on the page I am using it on.

like image 668
GSto Avatar asked Jul 03 '13 11:07

GSto


People also ask

How do I change the data in a Google chart?

Double-click the chart you want to change. At the right, click Setup. Select the cells you want to include in your chart. Optional: To add more data to the chart, click Add another range.

How do I hide the legend in my Google chart?

The Legend is hidden by setting the legend property to none in the Google Chart Options. title: 'USA City Distribution', legend: 'none' // Hides the Legend.


1 Answers

What's happening now is that the chart takes your string, parses it to a Javascript Date object, and then uses the chart's default display options to show the date.

According to the Google Charts Docs, you can pass an option format to the axes using the ICU Pattern Set. So for example, you would specify hAxis.format = "MM/dd/yy" to get "03/03/13".

Using Chartkick, you should be able to use the :library syntax to pass options.

like image 158
Oliver Avatar answered Oct 01 '22 18:10

Oliver