Zooming by code on a date range

TeeChart for ActiveX, COM and ASP
Guilz
Newbie
Newbie
Posts: 46
Joined: Mon Nov 13, 2006 12:00 am

Zooming by code on a date range

Post by Guilz » Thu Sep 24, 2009 6:46 am

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Zooming by code on a date range

Post by Yeray » Thu Sep 24, 2009 9:54 am

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
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Guilz
Newbie
Newbie
Posts: 46
Joined: Mon Nov 13, 2006 12:00 am

Re: Zooming by code on a date range

Post by Guilz » Thu Sep 24, 2009 10:44 am

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Zooming by code on a date range

Post by Yeray » Thu Sep 24, 2009 11:37 am

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Guilz
Newbie
Newbie
Posts: 46
Joined: Mon Nov 13, 2006 12:00 am

Re: Zooming by code on a date range

Post by Guilz » Thu Sep 24, 2009 2:29 pm

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Zooming by code on a date range

Post by Yeray » Thu Sep 24, 2009 3:07 pm

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Guilz
Newbie
Newbie
Posts: 46
Joined: Mon Nov 13, 2006 12:00 am

Re: Zooming by code on a date range

Post by Guilz » Thu Sep 24, 2009 3:16 pm

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
Attachments
Teechart.jpg
Teechart.jpg (76.64 KiB) Viewed 13397 times

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Zooming by code on a date range

Post by Yeray » Thu Sep 24, 2009 3:36 pm

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
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Guilz
Newbie
Newbie
Posts: 46
Joined: Mon Nov 13, 2006 12:00 am

Re: Zooming by code on a date range

Post by Guilz » Thu Sep 24, 2009 3:40 pm

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

Guilz
Newbie
Newbie
Posts: 46
Joined: Mon Nov 13, 2006 12:00 am

Re: Zooming by code on a date range

Post by Guilz » Fri Sep 25, 2009 8:28 am

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
Attachments
t1.jpg
t1.jpg (181.55 KiB) Viewed 13381 times
t2.jpg
t2.jpg (189.01 KiB) Viewed 13382 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Zooming by code on a date range

Post by Narcís » Fri Sep 25, 2009 3:33 pm

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
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Guilz
Newbie
Newbie
Posts: 46
Joined: Mon Nov 13, 2006 12:00 am

Re: Zooming by code on a date range

Post by Guilz » Fri Sep 25, 2009 3:40 pm

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Zooming by code on a date range

Post by Narcís » Fri Sep 25, 2009 4:19 pm

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Guilz
Newbie
Newbie
Posts: 46
Joined: Mon Nov 13, 2006 12:00 am

Re: Zooming by code on a date range

Post by Guilz » Mon Sep 28, 2009 7:03 am

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Zooming by code on a date range

Post by Yeray » Mon Sep 28, 2009 11:29 am

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
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply