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  
 
 [ 2 post ] 

 Relevant Pages 

1. Automating Graph X Axis Scales

2. Graph Y Axis Scaling and %

3. Graphing - Data Axis scale Range.

4. Need non-linear curve fitting algorithm

5. MSChart axes and scales

6. MSChart axis labels and scales has got me stumped

7. MSChart axes scaling problem (VB5 Pro)

8. Excel/VBA graphics: Settings X-axis scale properties in VBA

9. Different Axis Scale

10. Changing axis scale when using MSChart

11. MS Chart: Prevent Y-axis scale going exponential??

12. MSChart and 2nd Y axis Scaling Problem

 

 
Powered by phpBB® Forum Software