show trend on a zoomed area

TeeChart for ActiveX, COM and ASP
Post Reply
aligator32
Newbie
Newbie
Posts: 3
Joined: Tue Jan 24, 2012 12:00 am

show trend on a zoomed area

Post by aligator32 » Thu Aug 23, 2012 7:56 am

Hi, how it is possible to show a trend line on a zoomed area ? the trend stays allways on the full serial , is this possible to fix the first element and the last to include in the calculation of the trend?
regards
JP

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

Re: show trend on a zoomed area

Post by Yeray » Thu Aug 23, 2012 10:08 am

Hi,

You could populate a dummy series with only the visible values at OnZoom event, and show the Trend of this dummy series.
Ie:

Code: Select all

Private Sub Form_Load()    
  TChart1.Aspect.View3D = False
  
  TChart1.AddSeries scBar
  TChart1.Series(0).Name = "Source"
  TChart1.Series(0).FillSampleValues 50
  
  TChart1.AddSeries scBar
  TChart1.Series(1).Name = "Dummy"
  TChart1.Series(1).ShowInEditor = False
  TChart1.Series(1).ShowInLegend = False
  TChart1.Series(1).Active = False
  
  TChart1.AddSeries scLine
  TChart1.Series(2).Name = "Trend"
  TChart1.Series(2).SetFunction tfTrend
  TChart1.Series(2).DataSource = TChart1.Series(1)
End Sub

Private Sub TChart1_OnZoom()
  TChart1.Environment.InternalRepaint
  TChart1.Series(1).Clear
  Dim i As Integer
  For i = TChart1.Series(0).FirstValueIndex To TChart1.Series(0).LastValueIndex
    TChart1.Series(1).AddXY TChart1.Series(0).XValues.Value(i), TChart1.Series(0).YValues.Value(i), "", clTeeColor
  Next i

  TChart1.Series(2).DataSource = TChart1.Series(1)
  TChart1.Series(2).CheckDataSource
End Sub
If you want to get the Trend line of all the values when you zoom out, you could use the OnUndoZoom for it. Then you could use the source series with the trend function:

Code: Select all

Private Sub TChart1_OnUndoZoom()
  TChart1.Series(2).DataSource = TChart1.Series(0)
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

aligator32
Newbie
Newbie
Posts: 3
Joined: Tue Jan 24, 2012 12:00 am

Re: show trend on a zoomed area

Post by aligator32 » Thu Aug 23, 2012 1:07 pm

Hi,
Thanks a lot, I did it, it's fine...
regards
JP

Post Reply