I recently created a site that creates charts with google charts api
and information it collects from a database that the owner of the site
inputs. All works well except for the left and right axis top numbers.
These display odd top numbers and I am wondering what it would take to
get it to round the number up to the nearest 100 so that it displays
evenly.

I set the code to go 100 over and I think that somewhere in here is my
problem. If a user inputs a number of 255 and that number is the
highest within the chart data then the top number displays 355. It
displays both top number 255 and 355. Now what this does is makes the
gains look higher that they actually are because it goes from 200, 255
and then 355.

Please see example out put here

I am sure there must be away to dynamically add the axis labels
without it pulling in the info from the data itself right?

I have asked this very same question on google code and still know answer.

Here is an example of the code I am using.

<?php

$id_entity = $_product->getId();

    $chart_num_rows = 0;

    $db_obj = mysql_connect('localhost', 'XXX', 'XXX');

    mysql_select_db('XXXX', $db_obj);

    $query = "
    SELECT
    a.frontend_label AS frontend_label,
    b.value AS value
    FROM XXX AS a, XXX AS b
    WHERE a.attribute_id = b.attribute_id
    && b.entity_id = ".$id_entity."
    && a.attribute_id BETWEEN 564 AND 568
    ORDER BY a.attribute_id ASC
    ";

    $result = mysql_query($query);

    if(mysql_num_rows($result) != 0) {

            @$chart_num_rows = mysql_num_rows($result);
    }

    if($chart_num_rows != 0) {

            $max = 0;

            $min = 0;

            $array = array();

            for($i = 0; $i < $chart_num_rows; $i++) {

                    $row = mysql_fetch_object($result);

                    $clean = str_replace(" ", '', $row->value);

                    $explode = explode(',', $clean);

                    if($i == 4) {

                            $min = min($explode);

                            $max = max($explode);

                    } else {

                            if($min < min($explode)) {

                                    $min = min($explode);
                            }

                            if($max < max($explode)) {

                                    $min = max($explode);
                            }

                    }

                    $array[$i][0] = $row->frontend_label;  /* Labels */
                    $array[$i][1] = $clean;      /* Line Data */
                    $array[$i][2] = str_replace(',', '|', $clean);  /* Labels */

            }

            $count = 100;

            $left_right = '';

            while($count < $max) {

                    $left_right .= $count.'|';

                    $count = ($count + 100);

            }

            $left_right .= $max.'|'.($max + 100);

            $output = '<img src="http://chart.apis.google.com/chart?
cht=lc&chd=t:'.$array[1][1].'|'.$array[2][1].'|'.$array[3][1].'|'.$array[4][1];
                $output .= '&chls=3|3|3|3|3|3,6,3&chf=bg,s,FFFFFF&chxl=0:|'.$array[0]
[2].'|1:|'.$left_right.'|2:|'.$left_right;
                $output .= '&chs=575x300&chf=bg,s,FFFFFFchco=444444,444444,0000FF,0000FF&chxt=x,y,rchds=50,'.($max + 100);
                $output .= '&chm=h,76A4FB,0,0:1:.2,2,-1|V,76A4FB,0,::2,0.5,-1"><br /

<br />';

    } else {

            $output = 'There are no current statistics available for this chart.';

    }

echo $output;

?> 
    Write a Reply...