Axis min/max for visible data only

TeeChart for ActiveX, COM and ASP
Post Reply
Rossmc
Newbie
Newbie
Posts: 23
Joined: Thu Mar 30, 2006 12:00 am

Axis min/max for visible data only

Post by Rossmc » Wed Jul 25, 2007 1:52 pm

In the sample code below the rs contains 12400 records.

I set the bottom axis so I am only displaying the last 260 points.

How can I get the chart to scale the left axis to the maximum and minimum values visibly displayed?

#SAMPLE
With tc
.Environment.MouseWheelScroll = False
.RemoveAllSeries
.AddSeries scLine

.Axis.Left.MaximumOffset = 10
.Axis.Left.MinimumOffset = 10

.Series(0).VerticalAxis = aLeftAxis
.Series(0).DataSource = rs
.Series(0).YValues.ValueSource = "prClose"

.Axis.Bottom.SetMinMax (rs.RecordCount - 260), rs.RecordCount

#THE NEXT LINE SCALES ACCORDING TO THE WHOLE SERIES
.Axis.Left.SetMinMax .Series(0).YValues.Minimum, .Series(0).YValues.Maximum

End With

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Jul 26, 2007 10:42 am

Hi,

you can use the MinVisibleValue and MaxVisibleValue methods, i.e. : :

Code: Select all

Private Sub Form_Load() 
TChart1.Series(0).FillSampleValues (10)
TChart1.Axis.Bottom.SetMinMax 5, 8
  TChart1.Environment.InternalRepaint
End Sub

Private Sub TChart1_OnAfterDraw()
With TChart1
    .Axis.Left.SetMinMax .Series(0).MinVisibleValue(1), .Series(0).MaxVisibleValue(1)
End With
End Sub

Rossmc
Newbie
Newbie
Posts: 23
Joined: Thu Mar 30, 2006 12:00 am

Sorry

Post by Rossmc » Thu Jul 26, 2007 1:29 pm

That was actually a bit embarressing since even doing it manually wasn't exactly rocket-science!

I think I do have a real question now though.

Same basic chart as before, ie, 12000 points, looking at 260 at a time. I want to enable the scroll feature - horizontal only - with the left mouse button. Using the built in scroll ability of the control works really well but I want it to stop at the left extent, ie. not scroll past a minimum x axis value of 1. I do want them to be able to scroll into the future so that is fine.

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Jul 26, 2007 8:20 pm

Hi,

you can use the OnScroll event, like in the below example :

Code: Select all

Private Sub Form_Load()
With TChart1
    .AddSeries scLine
    .Series(0).FillSampleValues (10)
    .Scroll.Enable = pmHorizontal
    .Zoom.MouseButton = mbRight
    .Scroll.MouseButton = mbLeft
    .Environment.InternalRepaint
End With
End Sub

Private Sub TChart1_OnAfterDraw()
With TChart1
    .Axis.Left.SetMinMax .Series(0).MinVisibleValue(1), .Series(0).MaxVisibleValue(1)
End With
End Sub

Private Sub TChart1_OnScroll()
If TChart1.Axis.Bottom.Minimum < 1 Then
    TChart1.Axis.Bottom.SetMinMax 1, TChart1.Axis.Bottom.MaxVisibleSeriesValue(True, 0)
End If
End Sub

Private Sub Command2_Click()
TChart1.Axis.Bottom.SetMinMax 3, 8
End Sub

Private Sub Command1_Click()
TChart1.Series(0).Add Rnd * 100, "", clTeeColor
End Sub

Post Reply