Google chart API: how can I change the date format on the axis?

I have a google chart (configured using chartkick. And I'm trying to make dates shorter on the chart. Set looks something like this:

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

However, when I download the chart, the date is formatted like this: March 1, 2013. How can I get the date to display when I transmitted it, or in some other short format? The longer margins looked very closely on the page on which I use it.

+4
source share
2 answers

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

According to the Google Charts Docs, you can pass the format option on the axis using a set of ICU templates . For example, you must specify hAxis.format = "MM/dd/yy" to get "03/03/13" .

Using Chartkick, you can use the :library syntax to pass options .

+11
source

Hope this helps you. Use this line inside the options.

 var options = { format: 'dd-MMM-yyyy' } 

Take a look at this for a working sample. jqfaq.com

0
source

Source: https://habr.com/ru/post/1489469/


All Articles