SimonSellick
Programmer
I'm building simple line charts in PHP and need to choose sensible y-axis limits for the data provided, probably along the lines of the 1, 2, 5 series. The x-axis values are just labels (e.g. month, week) and are provided for me.
The y-ordinates could be any value within sensible limits, for example 0.001 - 1000000. I'll ignore negative values for now, and I am interested only in a linear scale starting at 0. Although there is a wide possible range, any one graph would have all of its values within about an order of magnitude of each other.
I want a y-axis scale that puts the highest value reasonably near the top of the graph, and has sensible-looking maximum and intermediate grid labels.
For example, if the y values were
{0.03, 0.5, 1.1, 0.66}
..then I would want the y axis to be
{0, 0.2, 0.4, ..., 2.0}.
If they were
{7501, 8800, 6943, 1311}
..then I would want
{0, 1000, 2000, ..., 10000}.
I can see how to do this by (1) either analysing and altering a string conversion of the highest y-ordinate found, or by looping through a scaling routine; then (2) reconverting the massaged string to a number and performing a load of comparisons, but can anyone point me towards a more elegant solution?
[this seems to be a similar problem to which hasn't been answered]
Thanks in advance.
Simon.
The y-ordinates could be any value within sensible limits, for example 0.001 - 1000000. I'll ignore negative values for now, and I am interested only in a linear scale starting at 0. Although there is a wide possible range, any one graph would have all of its values within about an order of magnitude of each other.
I want a y-axis scale that puts the highest value reasonably near the top of the graph, and has sensible-looking maximum and intermediate grid labels.
For example, if the y values were
{0.03, 0.5, 1.1, 0.66}
..then I would want the y axis to be
{0, 0.2, 0.4, ..., 2.0}.
If they were
{7501, 8800, 6943, 1311}
..then I would want
{0, 1000, 2000, ..., 10000}.
I can see how to do this by (1) either analysing and altering a string conversion of the highest y-ordinate found, or by looping through a scaling routine; then (2) reconverting the massaged string to a number and performing a load of comparisons, but can anyone point me towards a more elegant solution?
[this seems to be a similar problem to which hasn't been answered]
Thanks in advance.
Simon.