Scaling Algorithm for Linear Graph Axis
Author Message Scaling Algorithm for Linear Graph Axis

Hi there:

I'm looking for algorithms to determine the optimum scale for a linear graph axis in VB3.0. Specifically, I'm
reading in an array of data that can have any possible numeric value. After determining the max and min
values, I need to plot the data on a linear graph axis. What I'm looking for is an alogrithm that will help me set
the graph scale to an aesthetic range based on the max and min values of the data. For example, if my data
range from -29.6 to +378.4 I would like to have a graph scale that ranged from say, -50 to +400, or something
equally as sensible. Basing the scale just on the max and min values results in a very unappealing graph. The
challenge here is that the data can contain any numeric value and that the scale must be linear (a log scale
is relatively easy to implement).

Anyone got any ideas or sources of information on this? Many thanks in advance!

P.S. I've already abandoned the Graph control since it can't supply the format I need :(

Sat, 15 Aug 1998 03:00:00 GMT  Scaling Algorithm for Linear Graph Axis

Quote:

> I'm looking for algorithms to determine the optimum scale for a
> linear graph axis in VB3.0. Specifically, I'm reading in an array of
> data that can have any possible numeric value. After determining the
> max and min values, I need to plot the data on a linear graph axis.
> What I'm looking for is an alogrithm that will help me set the graph
> scale to an aesthetic range based on the max and min values of the
> data.

[SNIP!]

Here's what I use - I hope it's of some use...
(Note that this routine allows you to use a reversed scale
where ScaleMax < ScaleMin)

'-------------------------------------------------------
' Compute scale and number of ticks for graph to display
' values ranging between DataMin and DataMax.
'
Sub Ticks_Compute (ScaleMin As Single, ScaleMax As Single, ScaleTicks
As Integer, ByVal DataMin As Single, ByVal DataMax As Single)

Dim DataMul As Single
Dim DataExt As Single
Dim GuessMul As Single

DataExt = Abs(DataMax - DataMin)
If DataExt > 0 Then
GuessMul = 10 ^ Int(Log(DataExt) / Log(10))

Select Case DataExt / GuessMul
Case Is >= 8: ScaleMul = GuessMul * 2
Case Is >= 4: ScaleMul = GuessMul * 1
Case Is >= 2: ScaleMul = GuessMul * .5
Case Is >= 1.25: ScaleMul = GuessMul * .25
Case Is >= 1: ScaleMul = GuessMul * .2
End Select

ScaleMin = Int(DataMin / ScaleMul + .2) * ScaleMul
ScaleMax = Int(DataMax / ScaleMul + .8) * ScaleMul
ScaleTicks = Int(Abs(ScaleMax - ScaleMin) / ScaleMul)
Else
ScaleMin = DataMin
ScaleMax = DataMax
ScaleTicks = 1
End If

End Sub

--
Alasdair McIntyre

Mon, 24 Aug 1998 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages