TrendLine Issues

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

TrendLine Issues

Post by nefis » Wed Apr 14, 2004 5:26 am

Hi,
the form below creates a trendline on "Add Line" button pressing. Then it creates second line which extends the first one. When an user selects the extention line it tries to switch to first (main) line since the latter should be used to handle dragging for both lines.
Firstly, the second line is invisible until the chart is refreshed.
Secondly, switching selection doesn't work

Could you give me a workaround to emulate the needed behavior?

nefis

Code: Select all

VERSION 5.00
Object = "{54294AC6-FA71-4C7F-B67C-6C6405DFFD48}#1.0#0"; "TeeChart6.ocx"
Begin VB.Form Form1 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Form1"
   ClientHeight    =   9705
   ClientLeft      =   1590
   ClientTop       =   495
   ClientWidth     =   13725
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   9705
   ScaleWidth      =   13725
   ShowInTaskbar   =   0   'False
   Begin TeeChart.TChart TChart1 
      Height          =   9180
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   13710
      Base64          =   $"Form1.frx":0000
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Add Line"
      Height          =   375
      Left            =   12480
      TabIndex        =   1
      Top             =   9300
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim Xd As Double
Dim Yd As Double

Private Sub Command1_Click()
  Dim lt As TeeChart.IDrawLineTool
  Dim L As Long
  Dim L2 As Long
  
  If Xd = 0 Then
    Xd = TChart1.Axis.Bottom.Maximum - TChart1.Axis.Bottom.Minimum
  End If
  If Yd = 0 Then
    Yd = TChart1.Axis.Left.Maximum - TChart1.Axis.Left.Minimum
  End If

  Set lt = TChart1.Tools.Items(TChart1.Tools.Add(tcDrawLine)).asDrawLine
  With lt
    L = .AddLine(0, 0, 1, 1)
    lt.Lines.Items(L).StartPos.X = TChart1.Axis.Bottom.Minimum + Rnd * Xd
    lt.Lines.Items(L).StartPos.Y = TChart1.Axis.Right.Minimum + Rnd * Yd
    lt.Lines.Items(L).EndPos.X = TChart1.Axis.Bottom.Minimum + Rnd * Xd
    lt.Lines.Items(L).EndPos.Y = TChart1.Axis.Right.Minimum + Rnd * Yd
    L2 = .AddLine(0, 0, 1, 1)
    lt.Lines.Items(L2).StartPos.X = lt.Lines.Items(L).EndPos.X
    lt.Lines.Items(L2).StartPos.Y = lt.Lines.Items(L).EndPos.Y
    lt.Lines.Items(L2).EndPos.X = lt.Lines.Items(L).EndPos.X + 10 * (lt.Lines.Items(L).EndPos.X - lt.Lines.Items(L).StartPos.X)
    lt.Lines.Items(L2).EndPos.Y = lt.Lines.Items(L).EndPos.Y + 10 * (lt.Lines.Items(L).EndPos.Y - lt.Lines.Items(L).StartPos.Y)
    lt.EnableDraw = False
  End With
End Sub

Private Sub Form_Load()
  Dim i As Long
  TChart1.Aspect.View3D = False
  TChart1.Legend.Visible = False
  Call TChart1.AddSeries(scCandle)
  Call TChart1.Series(0).FillSampleValues(100)
  TChart1.Series(0).VerticalAxis = aBothVertAxis
  TChart1.Axis.Left.Labels.Visible = False
End Sub

Private Sub TChart1_OnDrawLineToolSelectLine()
  Dim i As Long
  For i = 0 To TChart1.Tools.Count - 1
    If TChart1.Tools.Items(i).ToolType = tcDrawLine Then
      If TChart1.Tools.Items(i).asDrawLine.Selected <> -1 Then
        TChart1.Tools.Items(i).asDrawLine.Selected = 0
      End If
    End If
  Next i
  Call TChart1.Repaint
End Sub

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 » Wed Apr 14, 2004 1:35 pm

Hi --
Could you give me a workaround to emulate the needed behavior?
Try:

Code: Select all

Private Sub Command1_Click()
  
  Dim T As Long
  Dim L As Long
  Dim L2 As Long
  Dim lt As TeeChart.IDrawLineTool
  Dim FromX As Double
  Dim FromY As Double
  Dim ToX As Double
  Dim ToY As Double
  
  If Xd = 0 Then
    Xd = TChart1.Axis.Bottom.Maximum - TChart1.Axis.Bottom.Minimum
  End If
  If Yd = 0 Then
    Yd = TChart1.Axis.Left.Maximum - TChart1.Axis.Left.Minimum
  End If
  
  Set lt = TChart1.Tools.Items(TChart1.Tools.Add(tcDrawLine)).asDrawLine
  With lt
    .EnableDraw = False
    FromX = TChart1.Axis.Bottom.Minimum + Rnd * Xd
    FromY = TChart1.Axis.Right.Minimum + Rnd * Yd
    ToX = TChart1.Axis.Bottom.Minimum + Rnd * Xd
    ToY = TChart1.Axis.Right.Minimum + Rnd * Yd
    L = .AddLine(FromX, FromY, ToX, ToY)

    FromX = lt.Lines.Items(L).EndPos.X
    FromY = lt.Lines.Items(L).EndPos.Y
    ToX = lt.Lines.Items(L).EndPos.X + 10 * (lt.Lines.Items(L).EndPos.X - lt.Lines.Items(L).StartPos.X)
    ToY = lt.Lines.Items(L).EndPos.Y + 10 * (lt.Lines.Items(L).EndPos.Y - lt.Lines.Items(L).StartPos.Y)
    
    L2 = .AddLine(FromX, FromY, ToX, ToY)
   
  End With
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 » Thu Apr 15, 2004 6:32 am

hi,
thanks for the workaround, but there is another issue:
Secondly, switching selection doesn't work
try to select the extension line. By code the "main" trendline should be selected but it's not :(

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 » Thu Apr 15, 2004 8:45 am

Hi --
try to select the extension line. By code the "main" trendline should be selected but it's not
This problem is associated with one that is already on the defect list for TeeChart Pro, meaning that a fix to it will be considered for inclusion into the next maintenance release.

In the meantime, I'm afraid, I can't suggest a workaround to it.
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