Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format a time as hours:minutes on a Google Charts y-axis

I have a Google Chart where the y-axis is measured in minutes.

How can I format the y-axis so the labels display the time in a format like 2hrs40, or 2:40, or something similar? I don't want to display the time in raw minutes, and I don't want to display it as a decimal like "1.5" for 90 minutes.

The documentation tells me to use the ICU Pattern Set, but I can't figure it out from that page.

Is this possible? And if I can't format the time like this directly, is there a way I can "hack" the chart after the fact by changing the <svg> element using Javascript?

like image 665
GMA Avatar asked Nov 05 '13 03:11

GMA


People also ask

How do you change the y axis values on a Google chart?

Customize the axesDouble-click the chart you want to change. At the right, click Customize. Click Vertical axis. Make the changes you want.

How do I format axis in Google Sheets?

By default, Google Sheets will choose a scale for the x-axis and y-axis that ranges roughly from the minimum to maximum values in each column. To change the scale of the x-axis, simply double click any value on the x-axis. This will bring up the Chart editor panel on the right side of the screen.

How do you do a log scale in Google Sheets?

Double-click on the chart to bring up Chart editor. Go to the Customize tab. Open the Vertical axis tab and check Log scale. Open the Horizontal axis tab and check Log scale.

How do I show date and time in Excel chart?

In the chart, right-click the category axis, and then click Format Axis. In the Format Axis pane, select the Axis Options tab. Expand Axis Options, and then under Axis Type, make sure Date axis is selected. Under Units, next to Base, select Days, Months, or Years.


1 Answers

The formatting options don't allow you to do that. You can, however, use the vAxis.ticks option to manually specify the values to use for the tick marks and the strings you want to use to represent the values. The vAxis.ticks option takes an array of objects, where each object has v (value) and f (formatted value - what gets displayed on the chart) properties. Something like this should work:

vAxis: {
    ticks: [{v: 0, f: '0:00'}, {v: 30, f: '0:30'}, {v: 60, f: '1:00'}, {v: 90, f: '1:30'}]
}
like image 169
asgallant Avatar answered Nov 15 '22 14:11

asgallant