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.


Reply via email to