Capturing values from a selection on a graphic

TeeChart for ActiveX, COM and ASP
Post Reply
JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Capturing values from a selection on a graphic

Post by JAV » Mon May 23, 2011 4:44 pm

We need to select on a graphic in which we have several series FastLine type (in the x-axis are dates and the y-axis are numeric data), using a zoom box or something similar, and capture the minimum and maximum values in each of the axes from the selection

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

Re: Capturing values from a selection on a graphic

Post by Yeray » Tue May 24, 2011 11:25 am

Hello JAV,

I'm afraid you should do it manually using the mouse events and the axes CalcPosPoint functions to translate the mouse positions (in pixels) to the axis values. Here you have an example. Note that I've disabled the Zoom feature as it would create some conflicts with the manually drawn rectangle.

Code: Select all

Dim MouseDownX, MouseDownY, MouseActX, MouseActY As Integer

Private Sub Form_Load()  
  TChart1.Aspect.View3D = False
  TChart1.Zoom.Enable = False
  
  Dim i As Integer
  For i = 0 To 3
    TChart1.AddSeries scFastLine
    TChart1.Series(i).XValues.DateTime = True
    TChart1.Series(i).FillSampleValues
  Next i
  
  MouseDownX = -1
  MouseDownY = -1
End Sub

Private Sub TChart1_OnMouseDown(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
  MouseDownX = X
  MouseDownY = Y
End Sub

Private Sub TChart1_OnAfterDraw()
  If (MouseDownX > -1) And (MouseDownY > -1) Then
    With TChart1.Canvas
      .Brush.Style = bsClear
      .Pen.Style = psDot
      .Pen.Color = vbGrayText
      .Rectangle MouseDownX, MouseDownY, MouseActX, MouseActY
    End With
  End If
End Sub

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
  If (MouseDownX > -1) And (MouseDownY > -1) Then
    MouseActX = X
    MouseActY = Y
    TChart1.Repaint
  End If
End Sub

Private Sub TChart1_OnMouseUp(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
  If (MouseDownX < MouseActX) Then
    Caption = "MinX: " + FormatDateTime(TChart1.Axis.Bottom.CalcPosPoint(MouseDownX)) + " - MaxX: " + FormatDateTime(TChart1.Axis.Bottom.CalcPosPoint(MouseActX))
    AddYValuesToCaption
  Else
    Caption = "MinX: " + FormatDateTime(TChart1.Axis.Bottom.CalcPosPoint(MouseActX)) + " - MaxX: " + FormatDateTime(TChart1.Axis.Bottom.CalcPosPoint(MouseDownX))
    AddYValuesToCaption
  End If
  
  MouseDownX = -1
  MouseDownY = -1
End Sub

Private Sub AddYValuesToCaption()
  If (MouseDownY > MouseActY) Then
    Caption = Caption + " - MinY: " + Format(TChart1.Axis.Left.CalcPosPoint(MouseDownY)) + " - MaxY: " + Format(TChart1.Axis.Left.CalcPosPoint(MouseActY))
  Else
    Caption = Caption + " - MinY: " + Format(TChart1.Axis.Left.CalcPosPoint(MouseActY)) + " - MaxY: " + Format(TChart1.Axis.Left.CalcPosPoint(MouseDownY))
  End If
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