Page 1 of 2

Zooming by code on a date range

Posted: Thu Sep 24, 2009 6:46 am
by 9533057
Hi,

I'd like to zoom by code selecting a date range.
For example, my chart has date on bottom axis and 5 years of data (since 2004) and I'd like to zoom on the specific range (between 2007 and 2008) by code (not by clicking on the chart to draw a rectangle zone with mouse)
How can I do that ?

Thanks a lot for your help.

Regards

Guilz

Re: Zooming by code on a date range

Posted: Thu Sep 24, 2009 9:54 am
by yeray
Hi Guilz,

A zoom simply consists on changing the axes minimum and maximum values. In your case you could do for example the following:

Code: Select all

Private Sub Form_Load()
  TChart1.Aspect.View3D = False
 
  TChart1.AddSeries scFastLine
  TChart1.Series(0).XValues.DateTime = True
  
  Dim month, year As Integer
  
  For year = 2004 To 2009
    For month = 1 To 12
      TChart1.Series(0).AddXY DateValue("1/" & Str$(month) & "/" & Str$(year)), Rnd * 100, "", clTeeColor
    Next month
  Next year
  
  DoZoom
End Sub

Private Sub DoZoom()
  TChart1.Axis.Bottom.SetMinMax DateValue("1/1/2007"), DateValue("1/1/2008")
End Sub

Private Sub UndoZoom() ' function to be called when you'll want to undo the zoom
  TChart1.Axis.Bottom.Automatic = True
End Sub

Re: Zooming by code on a date range

Posted: Thu Sep 24, 2009 10:44 am
by 9533057
Thanks Yeray :D

What is the best way to do the same when the bottom axis is not in datetime mode ?
I think it is necessary to find the label caption in the labels collection to get label index and to use the SetMinMax method. Is it right ?
Does it exist best method to do that ?

Regards,

Guilz

Re: Zooming by code on a date range

Posted: Thu Sep 24, 2009 11:37 am
by yeray
Hi Guilz,

If your bottom axis isn't datetime it is possible that the labels coincide with the values index but note that this is not necessary.

For more information about Zooming, please, take a look at the Tutorial 11 - Zoom and Scroll. You'll find demos and tutorials at TeeChart programs group.

If you still find problems with it, please, try to explain what are you exactly trying to do. A picture would probably help us to understand it better.

Re: Zooming by code on a date range

Posted: Thu Sep 24, 2009 2:29 pm
by 9533057
Thks Yeray, your help is very usefull :wink:
Looking the tutorial about zooming and scrolling, help speak about TChartScrollBar component but I don't able to find and use it (I use Tchart Pro v7).
How can I find it ?
Here components list available for me:
TeeChart
TeeListBox
TeeEditor
TeePreviewer
TeeCommander
TeePreviewPanel
ChartGridNavigator
ChartPageNavigator
ChartEditorPanel
ChartGrid
SeriesXMLSource
SeriesTextSource
CrossTabSource

Thank you Yeray

Guilz

Re: Zooming by code on a date range

Posted: Thu Sep 24, 2009 3:07 pm
by yeray
Hi Guilz,

It's strange, I think it should be included in v7. Could you please see if there is the unit TeeScroB.dcu present in the lib folder of your TeeChart installation path (Normally it should be something like C:\Program Files\Steema Software\TeeChart 8.06 for Delphi 2010\Delphi14\Lib).

Anyway, it is a component with some problems so we usually recommend not to use it and use a normal TScrollBar component and do the scroll through it.

Re: Zooming by code on a date range

Posted: Thu Sep 24, 2009 3:16 pm
by 9533057
I use Teechart with VB6.
Screenshot of the directory attached.

You speak about TScrollBar: what is the difference with TChartScrollBar ?
I don't have TScrollBar too :?

Guilz

Re: Zooming by code on a date range

Posted: Thu Sep 24, 2009 3:36 pm
by yeray
Hi Guilz,

Ouh, excuse me. When you talked about TChartScrollBar, I started to think in VCL terms; I forgot that we are in ActiveX.
It's strange, does your ActiveX tutorial talk about TChartScrollBar? Can you please tell me exactly where?

In VB6 there is the HScrollBar that is useful to do the scrolling. For example:

Code: Select all

Dim PointsShown As Integer

Private Sub Form_Load()
  TeeCommander1.Chart = TChart1
  
  TChart1.Aspect.View3D = False
  
  TChart1.AddSeries scLine
  TChart1.Series(0).asLine.Pointer.Visible = True
  TChart1.Series(0).FillSampleValues 25
  
  PointsShown = 5
    
  HScroll1.Min = 0
  HScroll1.Max = TChart1.Series(0).Count - PointsShown - 1
  HScroll1.Value = 0
  
  HScroll1_Change
End Sub

Private Sub HScroll1_Change()
  TChart1.Axis.Bottom.SetMinMax HScroll1.Value, HScroll1.Value + PointsShown
End Sub

Private Sub HScroll1_Scroll()
  HScroll1_Change
End Sub

Re: Zooming by code on a date range

Posted: Thu Sep 24, 2009 3:40 pm
by 9533057
I think Tutorial 11 - Zoom and Scroll is not specific for ActiveX component :D
So in my case, TChartScrollBar is not available :mrgreen: but if this component has some bug not a problem for me

Thks a lot for your sample.

Guilz

Re: Zooming by code on a date range

Posted: Fri Sep 25, 2009 8:28 am
by 9533057
Hi :D

Another day, another question :wink:
How can I adapt automaticaly optimal axis range (left axis) when I use setminmax function to zoom on a specific range (bottom axis) ?
Have a look to my screenshot, easier to understand.

Thanks for your help

Guilz

Re: Zooming by code on a date range

Posted: Fri Sep 25, 2009 3:33 pm
by narcis
Hi Guilz,

This is what TeeChart axes do automatically by default you can set axes to scale automatically and use their offset, for example:

Code: Select all

Private Sub Command1_Click()
    TChart1.Axis.Left.Automatic = True
    TChart1.Axis.Bottom.Automatic = True
    
    TChart1.Axis.Left.MinimumOffset = 50
    TChart1.Axis.Left.MaximumOffset = 50
    TChart1.Axis.Bottom.MinimumOffset = 50
    TChart1.Axis.Bottom.MaximumOffset = 50
End Sub

Private Sub Form_Load()
    TChart1.Axis.Left.SetMinMax 500, 1000
    TChart1.Axis.Bottom.SetMinMax 5, 10
End Sub

Re: Zooming by code on a date range

Posted: Fri Sep 25, 2009 3:40 pm
by 9533057
Hi narcis,

my axis automatic property are set to true but it does not reflect minimum and maximum values for the range define by setminmax method on bottom axis only -> on Left axis, min max values reflecting entire content of the graph.

Hope it help you to understand my problem :roll:

Thks a lot :wink:

Guilz

Re: Zooming by code on a date range

Posted: Fri Sep 25, 2009 4:19 pm
by narcis
Hi Guilz,

Ok, I think I understand what you are trying to achieve now. You could do something as the local minimum and maximum example suggested here. You could use series' FirstVisibleIndex and LastVisibleIndex as first and last arguments. This is a TeeChart .NET thread but same applies to TeeChart ActiveX.

Hope this helps.

Re: Zooming by code on a date range

Posted: Mon Sep 28, 2009 7:03 am
by 9533057
Hi Narcis,

Thanks for your answer but could you confirm me the FirstVisibleIndex and LastVisibleIndex properties are available for Teechart Pro 7.0 ActiveX because I can't find them :? Hope it is not only for .Net...

Guilz

Re: Zooming by code on a date range

Posted: Mon Sep 28, 2009 11:29 am
by yeray
Hi Guilz,

Yes, FirstVisibleIndex and LastVisibleIndex aren't available in TeeChart AX v7 but you can use MinVisibleValue and MaxVisibleValue as follows:

Code: Select all

Private Sub Form_Load()
  TChart1.Aspect.View3D = False
  
  TChart1.AddSeries scFastLine
  
  TChart1.Series(0).Add Rnd * 1000, "", clTeeColor
  Dim i As Integer
  For i = 0 To 10
    TChart1.Series(0).Add TChart1.Series(0).YValues.Value(TChart1.Series(0).Count - 1) + Rnd * 10 - 5, "", clTeeColor
  Next i
  
  TChart1.Series(0).Add Rnd * 100, "", clTeeColor
  For i = 0 To 20
    TChart1.Series(0).Add TChart1.Series(0).YValues.Value(TChart1.Series(0).Count - 1) + Rnd * 10 - 5, "", clTeeColor
  Next i
End Sub

Private Sub Command1_Click()
  TChart1.Axis.Bottom.SetMinMax 15, TChart1.Series(0).Count - 1
  AdjustLeftAxis
End Sub

Private Sub AdjustLeftAxis()
  TChart1.Environment.InternalRepaint
  TChart1.Axis.Left.SetMinMax TChart1.Series(0).MinVisibleValue(1), TChart1.Series(0).MaxVisibleValue(1)
End Sub