Is there a "Best Fit" option to auto-scale the axes?

2,921 views
Skip to first unread message

Rupert Breheny

unread,
Sep 7, 2010, 12:39:54 PM9/7/10
to Google Chart API
I want to automate my graph from some Analytics data, but I won't be
able to do a "get largest" hits function. Is there way to just have a
line graph automatically scale to make use of the full range of the
data and auto-populate the tick marks on the axes? I just need to
generate a URL for an image on a run once template for an email I need
to create.

KeithB

unread,
Sep 8, 2010, 9:01:54 AM9/8/10
to Google Chart API
Not at this time, no.

- Keith

Rupert Breheny

unread,
Sep 8, 2010, 9:18:03 AM9/8/10
to google-c...@googlegroups.com
Hi Keith,

Thanks for getting back to me.


> Not at this time, no.

I think we may struggle when we get a small amount of variation in the
data, with large numbers? You just get a big block of green with a
slightly wavy line on top.

Any plans for updates in the near future?

KeithB

unread,
Sep 8, 2010, 9:51:29 AM9/8/10
to Google Chart API
Sorry, I'm just a user, not a Chart API developer.

I believe the API was initially used internally and then made
available to us developers. As such, it's quite powerful, but there's
never been a "we'll make it look nice for you" kind of feature with
other charting tools. My guess is that it will never automatically
scale your data and attempt to create axis ticks/values, but maybe
someone on the Chart API team can chime in.

With Javascript on the client and various server-side technologies
that developers can use, are you sure you can't loop through all your
values? Somehow you're generating a list of values to pass into the
CHD parameter and it shouldn't be too CPU-intensive to find the min/
max values and calculate a suitable axis range. If you need help,
surely someone here on the forum has already done the work...

Good luck,
Keith

Nathan Raley

unread,
Sep 8, 2010, 9:58:14 AM9/8/10
to google-c...@googlegroups.com
You could determine a scale and size that suits what you seem to think is the best size for the individual aspects of a given chart, and use some tricks to determine the user's viewable screen size and scale according to %'s of that. 

For instance if you decided your chart looked best at width x and your viewable browser size was x2 then you can take what % of x2 x is and then once you have that you have a base.  Do this for the other "objects" that make up the chart.  Then you can use some tricks to determine the user's viewable browser area, apply the % of the size you determine above, and give that a go.  You should be able to make it scale relatively well that way.  Might not be the best way to do it but it would get you somewhere to start.  The biggest issue this would give you is that you have to make a cut off point somewhere down the line.

That would be your best bet atm.


--
You received this message because you are subscribed to the Google Groups "Google Chart API" group.
To post to this group, send email to google-c...@googlegroups.com.
To unsubscribe from this group, send email to google-chart-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-chart-api?hl=en.


Rupert Breheny

unread,
Sep 8, 2010, 10:18:59 AM9/8/10
to Google Chart API
Thanks for your excellent suggestions guys. The problem is that we are
creating a newsletter and have some very limited mail merge data
available to us, and I don't think we are going to be able to do any
processing on the incoming data - it's just a straight list of
figures. Had this been a webpage with JS, then I'm sure I could have
done something interesting with an array of values, but sadly we have
to just generate a static URL for an image and then leave it at that.
I'll see how it looks with just the data on no actual axes data, so at
least the trends will be visible.

Thanks again,
Rupert

Marcus Bointon

unread,
Sep 8, 2010, 10:20:40 AM9/8/10
to google-c...@googlegroups.com
On 8 Sep 2010, at 15:51, KeithB wrote:

> it shouldn't be too CPU-intensive to find the min/
> max values and calculate a suitable axis range. If you need help,
> surely someone here on the forum has already done the work...

I posted a simple php class to do this on my blog ages ago:
http://marcus.bointon.com/archives/88-Google-Charts-API-Simple-and-Extended-Encoders-in-PHP.html

It supports auto-scaling to a maximum and truncating below a minimum.

Marcus

Marcus Bointon

unread,
Sep 8, 2010, 10:23:56 AM9/8/10
to google-c...@googlegroups.com

Who says you have to point it directly at google? Why not point it at your own script so you get a chance to pre-process it? I do that anyway to work around the broken SSL cert on google.com. I'd guess you're probably already hosting images for your newsletters anyway, so it's not much further than that.

Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
UK resellers of info@hand CRM solutions
mar...@synchromedia.co.uk | http://www.synchromedia.co.uk/


George Birbilis

unread,
Jun 23, 2019, 7:34:32 AM6/23/19
to Google Chart API
probably they added it later on, posting here for future reference (see https://developers.google.com/chart/interactive/docs/gallery/linechart)

hAxis.viewWindowMode

Specifies how to scale the horizontal axis to render the values within the chart area. The following string values are supported:

  • 'pretty' - Scale the horizontal values so that the maximum and minimum data values are rendered a bit inside the left and right of the chart area. This will cause haxis.viewWindow.min and haxis.viewWindow.max to be ignored.
  • 'maximized' - Scale the horizontal values so that the maximum and minimum data values touch the left and right of the chart area. This will cause haxis.viewWindow.min and haxis.viewWindow.max to be ignored.
  • 'explicit' - A deprecated option for specifying the left and right scale values of the chart area. (Deprecated because it's redundant with haxis.viewWindow.min and haxis.viewWindow.max.) Data values outside these values will be cropped. You must specify an hAxis.viewWindow object describing the maximum and minimum values to show.

This option is only supported for a continuous axis.

Type: string
Default: Equivalent to 'pretty', but haxis.viewWindow.min and haxis.viewWindow.max take precedence if used.
Reply all
Reply to author
Forward
0 new messages