Page 1 of 1

After zoom, how to get max/min values of the axis ?

Posted: Mon Feb 28, 2011 9:22 pm
by 15052741
I have a graph and I would like to know the values of the MaxXValue, MinXValue, MaxYValue and MinYValue after the zoom. I have noticed that after the zoom these properties still have the previous values of the original graph prior the applied zoom.


The main problem is that I set :
TChart1.Axis.Bottom.Automatic = False
TChart1.Axis.Left.Automatic = False



and I perform the calculations for the max/min and the increment for the axis. Example: the increment is calculated to have the Y axis divided in 4 equal parts, which I have done with:

increment=(TChart1.Axis.Left.Maximum-TChart1.Axis.Left.Minimum)/2
TChart1.Axis.Left.Maximum=TChart1.Axis.Left.Maximum+increment
TChart1.Axis.Left.Minimum=TChart1.Axis.Left.Minimum-increment
TChart1.Axis.Left.Increment=increment

If I zoom the graph, by using the mouse to draw a rectangle, I would like to run the code above in order again in order to have the graph divided in 4 equal parts. Here the problem is that all events is fired before the method responsible to redraw the chart, and the Maximum e Minimum properties are not updated yet. If I use afterdraw event I always get in trouble with recursive call.

Re: After zoom, how to get max/min values of the axis ?

Posted: Tue Mar 01, 2011 2:46 pm
by yeray
Hi Angelo,

I think you could use that code in OnZoom event. The following code seems to work fine for me here:

Code: Select all

Private Sub Form_Load()  
  TChart1.Aspect.View3D = False
  TChart1.Legend.Visible = False
  
  TChart1.AddSeries scFastLine
  TChart1.Series(0).FillSampleValues 100
End Sub

Private Sub TChart1_OnZoom()
  RecalcAxis
End Sub

Private Sub RecalcAxis()
  Increment = (TChart1.Axis.Left.Maximum - TChart1.Axis.Left.Minimum) / 2
  TChart1.Axis.Left.Maximum = TChart1.Axis.Left.Maximum + Increment
  TChart1.Axis.Left.Minimum = TChart1.Axis.Left.Minimum - Increment
  TChart1.Axis.Left.Increment = Increment
End Sub
If that's not what you want, please try to arrange a simple example project we can run as-is to reproduce the problem here.