• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Google Charts / calculating Y axis display values

I'm working with Google Charts, and i'm building a chart to display the amount of hits a page has gotten in the past 30 minutes.

Here is an example of the chart

http://chart.apis.google.com/chart?...|0,15&chtt=Previous+30+Minutes&chts=000000,11

The hit values are hard coded into that link, but would be calculating dynamically in production.

As of right now in the chart the Y axis is based on a value of 100. It is charted with values of 0,20,40,60,80,100

I want this to be calcuated dynamically. For instance, if the max hits per 1 minute is 345, I'd want the Y value to be an even number and divisible by 5.. like maybe 500, so the count would be 0,100,200,300,400,500

To calculate this.. I guess I'd have to create some if/then statements, using the max value

Like..

if #max_value# between 0 and 10
set #max_y_value# = 10

if #max_value# between 11 and 100
set #max_y_value# = 100

if #max_value# between 101 and 200
set #max_y_value# = 200

if #max_value# between 201 and 300
set #max_y_value# = 300

if #max_value# between 301 and 400
set #max_y_value# = 400

if #max_value# between 401 and 500
set #max_y_value# = 500

if #max_value# between 501 and 800
set #max_y_value# = 800

if #max_value# between 801 and 1000
set #max_y_value# = 1000

if #max_value# between 1001 and 1500
set #max_y_value# = 1500

and so on


Does this seem like a reasonable way to approach this?
 
if you want even numbers (thats what I'm guessing) then it would be cleaner to do something like
set #max_y_value# = (#max_value# / 100) * 100;
(assuming integer division)

You could do a progressive scaling by doing something like
int power = log(#max_value#) / log(10) // Convert to base 10 log; Store in an int to whack off extra stuff.
int factor = pow(10, power);
set #max_y_value# = (#max_value# / factor) * factor;

integers, they're fun stuff.
 
Back
Top