I should have also mentioned that in addition to the explicit tick values,
you can also include explicit viewWindow: { min and max } so you can get
the effect of the 'pretty' mode by expanding the bounds yourself. The
algorithm for 'pretty' mode is to expand the minValue to maxValue range by
10%. Hope that helps.
On Mon, Aug 12, 2013 at 9:28 PM, Daniel LaLiberte <[email protected]>wrote:
> Hi Luke,
>
> The algorithm that google charts uses to determine the axis range and
> intervals between ticks is not as straightforward as what you have shown,
> since it generally tries several different strategies until it finds one
> that works "best".
>
> One alternative you might consider is that now you can provide a explicit
> array of tick values that will be used in google charts, so you can arrange
> that you will use the same ticks in your image charts. This is done by
> using a 'ticks' option within one of the axes structures, where the value
> of the option is an array of tick values, or instead of just the values,
> you can specify the formatted representation along with the value. So, for
> example, you might use this:
>
> vAxis: {
> ticks: [ {v: 0, f: 'zero'}, 10, 20, 30, 40, 50 ]
> }
>
> One difference to be aware of is that the 'pretty' mode of the
> viewWindowMode will not be used with the explicit ticks, and it will
> instead behave as if you have specified 'explicit' and use the lowest and
> highest values in the array of ticks as the bounds. We are considering how
> to combine this with the 'pretty' mode in a future version.
>
>
>
> On Mon, Aug 12, 2013 at 7:59 PM, Luke Bellamy <[email protected]>wrote:
>
>> Hi,
>> I'm using google charts (basic combo chart) on a web site. Awesome, no
>> problem with that. I wish to put this into a PDF. So what I did was using
>> the deprecated image charts to generate an image using the same data and
>> making them look the same. Works great.
>>
>> My issue is that the vertical axis intervals, min, and max are not the
>> same. I understand why and I prefer the 'pretty' axis scaling in google
>> charts. So I thought I would come up with an algorithm myself using the min
>> and max from the data to come up with the range and intervals. This is for
>> the old image charts. Works very well, but in a couple of scenarios I can
>> see it's not EXACTLY the same, although close. Note that these are very
>> basic charts so I'm not doing anything fancy. It would just be nice if they
>> looked identical.
>>
>> My question is, can I find the axis range and interval algorithm from
>> google charts somewhere? I did see the google visualization java code
>> available but code not find what I was after.
>> Here is the basic bit of code I have been tweaking in JAVA for image
>> charts to mirror the axis algorithm of google charts.
>>
>> // Take the Max/Min of all data values in all graphs
>> var totalMax = 345;
>> var totalMin = -123;
>>
>> // Figure out the largest number (positive or negative)
>> var biggestNumber = Math.max(Math.abs(totalMax),Math.abs(totalMin));
>>
>> // Round to an exponent of 10 appropriate for the biggest number
>> var roundingExp = Math.floor(Math.log(biggestNumber) / Math.LN10);
>> var roundingDec = Math.pow(10,roundingExp);
>>
>> // Round your max and min to the nearest exponent of 10
>> var newMax = roundHalfUp(totalMax/roundingDec)*roundingDec;
>> var newMin = roundHalfDown(totalMin/roundingDec)*roundingDec;
>>
>> // Determine the range of your values
>> var range = newMax - newMin;
>>
>> // Define the number of gridlines (default 5)
>> var gridlines = 5;
>>
>> // Determine an appropriate gap between gridlines
>> var interval = range / (gridlines - 1);
>>
>> // Round that interval up to the exponent of 10
>> var newInterval = roundHalfUp(interval/roundingDec)*roundingDec;
>>
>> // Re-round your max and min to the new interval
>> var finalMax = Math.ceil(totalMax/newInterval)*newInterval;
>> var finalMin = Math.floor(totalMin/newInterval)*newInterval;
>>
>>
>>
>> Thankyou,
>> Luke
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to
>> [email protected].
>> Visit this group at
>> http://groups.google.com/group/google-visualization-api.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
>
> --
> Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2>
> - 978-394-1058
> [email protected] <[email protected]> 562D 5CC, Cambridge MA
> [email protected] <[email protected]> 9 Juniper Ridge
> Road, Acton MA
>
--
Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2> -
978-394-1058
[email protected] <[email protected]> 562D 5CC, Cambridge MA
[email protected] <[email protected]> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.