views:

284

answers:

1

Hi,

I have created a graph in extJS and was wondering if people know of a general formula to calculate the major and minor units of the X-Axis.

I know Extjs should do it automatically, but its not working and want to do it manually any way as I am already setting the maximum and minimum values.

Thanks for any help : )

Some code I have already tried, doesnt look right and actually on some sets of data becomes unresponsive.

Its a line graph with two stores A and B.

I treid calculating a majorunit value depending on the values within the stores.

MajUnit = (Math.abs(A) > Math.abs(B) ? Math.abs(A) : Math.abs(B)) / 10.0;

calcUnits(MajUnit) is then called in an effort to calculate the unit I should have for the major gridline, then I divide this by two to get the minor unit.

Units = function(unit) {
                var exit = false;
                var tmpMaj = Math.round(unit);
                var i = 1.0;

                while (exit !== true && (unit != 0) && !isNaN(unit)) {
                    if (tmpMaj > 0) {
                        exit = true;
                    }
                    i = i * 10.0;
                    tmpMaj = Math.round(unit * i);
                }

                unit = tmpMaj / i;
                return unit;
            }'
A: 

This is similar to what I am trying to do? I've tried just taking the max value and taking off the min value then dividing this by 10, but this doesnt appear to work!

I'm banging my head, it must be a simple formula that does this!

Steve