Crosshair cursor

TeeChart for ActiveX, COM and ASP
Post Reply
nefis
Newbie
Newbie
Posts: 62
Joined: Wed Oct 22, 2003 4:00 am
Location: chicago

Crosshair cursor

Post by nefis » Fri Jan 16, 2004 7:42 am

Hello,

Try the code below. It's supposed to show crosshair cursor on multimpl custom axes. But it shows a moving verical cursor and immovable horizontal one. What's the problem?

nefis

Code: Select all

Private Sub Command1_Click()
  TChart1.Axis.Right.StartPosition = 0
  TChart1.Axis.Right.EndPosition = 50
  Call TChart1.AddSeries(scLine)
  TChart1.Series(1).FillSampleValues 100
  Call TChart1.Axis.AddCustom(False)
  TChart1.Axis.Custom(0).Otherside = True
  TChart1.Axis.Custom(0).StartPosition = 50
  TChart1.Axis.Custom(0).EndPosition = 100
  TChart1.Series(1).VerticalAxisCustom = 0
  TChart1.Tools.Items(0).asTeeCursor.Series = Array(0, 1)
End Sub

Private Sub Form_Load()
  TChart1.Aspect.View3D = False
  TChart1.Legend.Visible = False
  Call TChart1.AddSeries(scCandle)
  TChart1.Series(0).FillSampleValues 100
  TChart1.Series(0).VerticalAxis = aRightAxis
  TChart1.Axis.Left.MaximumOffset = 5
  TChart1.Axis.Left.MinimumOffset = 5
  TChart1.Axis.Bottom.MaximumOffset = 50
  Call TChart1.Tools.Add(tcCursor)
  TChart1.Tools.Items(0).asTeeCursor.FollowMouse = True
  TChart1.Tools.Items(0).asTeeCursor.Series = Array(0) 'Array(TChart1.Series(0), TChart1.Series(1))
  TChart1.Tools.Items(0).asTeeCursor.Style = cssBoth
End Sub

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

Post by Pep » Fri Jan 16, 2004 9:28 am

Hi Nefis,

the problem here is that there's not any series assigned to the TeeCursor, assign it to any using :
TChart1.Tools.Items(0).asTeeCursor.Series = TChart1.Series(0)
it will work fine.

But if you want to have a cursor that allow you to move around the entire chart with custom axis you should use the Canvas techniques as in the following example instead of the TeeCursor Tool :

Code: Select all

Dim MyX, MyY As Long

Private Sub Form_Load()
With TChart1
    .Aspect.View3D = False
    .AddSeries scLine
    .AddSeries scLine
    .AddSeries scLine
    .Series(0).FillSampleValues 100
    .Series(1).FillSampleValues 100
    .Series(2).FillSampleValues 100

    .Series(0).VerticalAxisCustom = .Axis.AddCustom(False)
    .Series(1).VerticalAxisCustom = .Axis.AddCustom(False)
    .Series(2).VerticalAxisCustom = .Axis.AddCustom(False)

    .Axis.Custom(0).EndPosition = 100
    .Axis.Custom(0).StartPosition = 66
    .Axis.Custom(0).AxisPen.Color = .Series(0).Color
    .Axis.Custom(1).EndPosition = 66
    .Axis.Custom(1).StartPosition = 33
    .Axis.Custom(1).AxisPen.Color = .Series(1).Color
    .Axis.Custom(2).EndPosition = 33
    .Axis.Custom(2).StartPosition = 0
    .Axis.Custom(2).AxisPen.Color = .Series(2).Color

    .Panel.MarginLeft = 10
End With
End Sub

Private Sub TChart1_OnAfterDraw()
With TChart1
    .Canvas.Pen.Color = vbCyan
    .Canvas.MoveTo MyX, .Axis.Top.Position
    .Canvas.LineTo MyX, .Axis.Bottom.Position
    .Canvas.MoveTo .Axis.Left.Position, MyY
    .Canvas.LineTo .Axis.Right.Position, MyY

End With
End Sub

Private Sub TChart1_OnBeforeDrawSeries()
With TChart1
    .Canvas.ClipRectangle .Axis.Left.Position, .Axis.Top.Position,
.Axis.Right.Position, .Axis.Bottom.Position
End With
End Sub

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X
As Long, ByVal Y As Long)
MyX = X
MyY = Y
TChart1.Repaint
End Sub

nefis
Newbie
Newbie
Posts: 62
Joined: Wed Oct 22, 2003 4:00 am
Location: chicago

Post by nefis » Fri Jan 16, 2004 12:24 pm

Pep wrote:Hi Nefis,

the problem here is that there's not any series assigned to the TeeCursor, assign it to any using :
TChart1.Tools.Items(0).asTeeCursor.Series = TChart1.Series(0)
it will work fine.
Of course there is the assignation.

Code: Select all

Private Sub Form_Load() 
  TChart1.Aspect.View3D = False 
  TChart1.Legend.Visible = False 
  Call TChart1.AddSeries(scCandle) 
  TChart1.Series(0).FillSampleValues 100 
  TChart1.Series(0).VerticalAxis = aRightAxis 
  TChart1.Axis.Left.MaximumOffset = 5 
  TChart1.Axis.Left.MinimumOffset = 5 
  TChart1.Axis.Bottom.MaximumOffset = 50 
  Call TChart1.Tools.Add(tcCursor) 
  TChart1.Tools.Items(0).asTeeCursor.FollowMouse = True 
the "missing" statement

Code: Select all

  TChart1.Tools.Items(0).asTeeCursor.Series = Array(0) 'Array(TChart1.Series(0), TChart1.Series(1))

Code: Select all

  TChart1.Tools.Items(0).asTeeCursor.Style = cssBoth 
End Sub 
Addidtionally, the help says
The Series array property is the list of Series to which Tool belongs. A Tool will only be associated with these series points.
Series property can be nil (none) applying the Tool globally to the Chart.

TeeChart Pro ActiveX Control Documentation. Copyright 1997-2003 Steema Software SL.
nefis

nefis
Newbie
Newbie
Posts: 62
Joined: Wed Oct 22, 2003 4:00 am
Location: chicago

Post by nefis » Sun Jan 18, 2004 4:22 pm

still waiting...

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Mon Jan 19, 2004 4:36 pm

Hi --

You could try working around this problem using code similar to the following:

Code: Select all

Private Sub Command1_Click()
  TChart1.Axis.Right.StartPosition = 0
  TChart1.Axis.Right.EndPosition = 50
  Call TChart1.AddSeries(scLine)
  TChart1.Series(1).FillSampleValues 100
  Call TChart1.Axis.AddCustom(False)
  TChart1.Axis.Custom(0).Otherside = True
  TChart1.Axis.Custom(0).StartPosition = 50
  TChart1.Axis.Custom(0).EndPosition = 100
  TChart1.Series(1).VerticalAxisCustom = 0
  TChart1.Tools.Items(0).asTeeCursor.Series = Array(0, 1)
End Sub

Private Sub Form_Load()
  TChart1.Aspect.View3D = False
  TChart1.Legend.Visible = False
  Call TChart1.AddSeries(scCandle)
  TChart1.Series(0).FillSampleValues 100
  
  'Workaround
  TChart1.Series(0).VerticalAxis = aBothVertAxis
  TChart1.Axis.Left.Labels.Visible = False
  
  TChart1.Axis.Left.MaximumOffset = 5
  TChart1.Axis.Left.MinimumOffset = 5
  TChart1.Axis.Bottom.MaximumOffset = 50
  Call TChart1.Tools.Add(tcCursor)
  TChart1.Tools.Items(0).asTeeCursor.FollowMouse = True
  TChart1.Tools.Items(0).asTeeCursor.Series = Array(0) 'Array(TChart1.Series(0), TChart1.Series(1))
  TChart1.Tools.Items(0).asTeeCursor.Style = cssBoth
End Sub
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

nefis
Newbie
Newbie
Posts: 62
Joined: Wed Oct 22, 2003 4:00 am
Location: chicago

Post by nefis » Tue Jan 20, 2004 7:05 am

Hello Chris,

the code is an improve but it still doesn't work as intended. When second line is added it ovelaps candle series. To fix it I've added a couple of lines

Code: Select all

Private Sub Command1_Click()
  TChart1.Axis.Right.StartPosition = 0
  TChart1.Axis.Right.EndPosition = 70

  'Added code
  TChart1.Axis.Left.StartPosition = 0
  TChart1.Axis.Left.EndPosition = 70
  'end added code

  Call TChart1.AddSeries(scLine)
  TChart1.Series(1).FillSampleValues 100
  Call TChart1.Axis.AddCustom(False)
  TChart1.Axis.Custom(0).Otherside = True
  TChart1.Axis.Custom(0).StartPosition = 70
  TChart1.Axis.Custom(0).EndPosition = 100
  TChart1.Series(1).VerticalAxisCustom = 0
  TChart1.Tools.Items(0).asTeeCursor.Series = Array(0, 1)
End Sub
but the result is frustrating. It draws the crosshair for the candle series only 8(

nefis

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Tue Jan 20, 2004 9:30 am

Hi --
but the result is frustrating. It draws the crosshair for the candle series only 8(
This issue has been discussed frequently in the past; try going to:
http://www.tamaracka.com/search.htm

and doing a search for:
cursor custom axes ^*teechart* ^*activex*

Basically, this is because Cursor Tools cannot operate across Custom
Axes. You will need to draw your own "Cursor Tool" in a manner similar to the following:

Code: Select all

Private Sub Form_Load()
Dim Axis As Integer
  With TChart1
    .Aspect.View3D = False
    .AddSeries scLine
    .AddSeries scLine
    .AddSeries scLine
    .Series(0).FillSampleValues (1000)
    .Series(1).FillSampleValues (1000)
    .Series(2).FillSampleValues (1000)
    ' create the axes...
    Axis = .Axis.AddCustom(False)
    .Axis.Custom(Axis).StartPosition = 30
    .Axis.Custom(Axis).EndPosition = 60
    .Axis.Custom(Axis).AxisPen.Color = .Series(1).Color
    .Series(1).VerticalAxisCustom = Axis
    Axis = .Axis.AddCustom(False)
    .Axis.Custom(Axis).StartPosition = 60
    .Axis.Custom(Axis).EndPosition = 100
    .Axis.Custom(Axis).AxisPen.Color = .Series(2).Color
    .Series(2).VerticalAxisCustom = Axis
    .Axis.Left.EndPosition = 30
  End With
End Sub

Private Sub TChart1_OnAfterDraw()
With TChart1
    .Canvas.Pen.Color = vbCyan
    .Canvas.Pen.Width = 3
    .Canvas.MoveTo .MousePosition.X, .Axis.Top.Position
    .Canvas.LineTo .MousePosition.X, .Axis.Bottom.Position
End With
End Sub

Private Sub TChart1_OnBeforeDrawSeries()
With TChart1
    .Canvas.ClipRectangle .Axis.Left.Position, .Axis.Top.Position, .Axis.Right.Position, .Axis.Bottom.Position
End With
End Sub

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
TChart1.Repaint
End Sub
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Post Reply