How to create profile section?

TeeChart for ActiveX, COM and ASP
Post Reply
zrandlbs
Newbie
Newbie
Posts: 37
Joined: Thu Dec 05, 2013 12:00 am

How to create profile section?

Post by zrandlbs » Fri Apr 04, 2014 8:44 am

Hi,Yeray
I used colorGrid to make a map.Now I want to draw a line on colorgrid and to create a profile section.Would you give me any suggestions?I do not know how to get the coordinates and values of the intersection points between the line and colorgrid.
Thanks,
Cheers,
Robinson

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

Re: How to create profile section?

Post by Yeray » Fri Apr 04, 2014 2:34 pm

Hi robinson,
zrandlbs wrote:I used colorGrid to make a map.Now I want to draw a line on colorgrid and to create a profile section.Would you give me any suggestions?I do not know how to get the coordinates and values of the intersection points between the line and colorgrid.
I'm not sure to understand what problem have you found when trying to do it.
I've been able to draw a ColorGrid and a Line series in the same chart:

Code: Select all

Private Sub Form_Load()
  TChart1.Header.Text.Clear
  TChart1.Header.Text.Add TChart1.Version
  TChart1.Aspect.View3D = False

  TChart1.AddSeries scColorGrid
  TChart1.Series(0).FillSampleValues
  
  TChart1.AddSeries scLine
  TChart1.Series(1).FillSampleValues
End Sub
ColorGrid+Line.png
ColorGrid+Line.png (73.03 KiB) Viewed 15882 times
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

zrandlbs
Newbie
Newbie
Posts: 37
Joined: Thu Dec 05, 2013 12:00 am

Re: How to create profile section?

Post by zrandlbs » Sun Apr 06, 2014 2:02 am

Hi,Yeray,
Thank for your quick reply.I used colorgrid to generate an image that the grid color is concentration of an element.Now I need to allow users to draw a line on my image to generate a section along the line. I need to get values of the colors and coordinates on the line.
Because the line is drawn by users,so I think I should use "draw line" tool.
I think the key problem is how to get the coordinates of crossing points between the drawn line and my image.I drew a picture for you. In my picture,Y axis is concentration of Al and x axis is distance of the drawn line on colorgrid.
Thanks,
Good luck!
Robinson
Attachments
questionA.jpg
questionA.jpg (163.56 KiB) Viewed 15864 times

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

Re: How to create profile section?

Post by Yeray » Mon Apr 07, 2014 11:50 am

Hi Robinson,
zrandlbs wrote:Thank for your quick reply.I used colorgrid to generate an image that the grid color is concentration of an element.Now I need to allow users to draw a line on my image to generate a section along the line. I need to get values of the colors and coordinates on the line.
Because the line is drawn by users,so I think I should use "draw line" tool.
I think the key problem is how to get the coordinates of crossing points between the drawn line and my image.I drew a picture for you. In my picture,Y axis is concentration of Al and x axis is distance of the drawn line on colorgrid.
The Clicked(X, Y) function of the ColorGrid will give you the index of the cell under a given pixel. However, you still have to calculate the list of pixels in that line, and I'm afraid you should do it manually. I've taken the code from here to make a simple example. Take it as a start point:

Code: Select all

Private Sub Command1_Click()
  checkLine
End Sub

Private Sub Form_Load()
  TeeCommander1.ChartLink = TChart1.ChartLink
  TChart1.Header.Text.Clear
  TChart1.Header.Text.Add TChart1.Version
  TChart1.Aspect.View3D = False

  TChart1.AddSeries scColorGrid
  TChart1.Series(0).FillSampleValues
  
  TChart1.Tools.Add tcDrawLine
  TChart1.Tools.Items(0).asDrawLine.EnableDraw = False
  
  TChart1.Tools.Items(0).asDrawLine.AddLine 0, 0, 5, 5
  
  'TChart1.Environment.InternalRepaint
  'MsgBox TChart1.Tools.Items(0).asDrawLine.Lines.Items(0).EndPos.x
End Sub

Private Sub checkLine()
  Dim i, X, tmp As Integer
  Dim X0, Y0, X1, Y1 As Integer
  
  X0 = TChart1.Axis.Bottom.CalcXPosValue(TChart1.Tools.Items(0).asDrawLine.Lines.Items(0).StartPos.X)
  Y0 = TChart1.Axis.Left.CalcYPosValue(TChart1.Tools.Items(0).asDrawLine.Lines.Items(0).StartPos.Y)
  X1 = TChart1.Axis.Bottom.CalcXPosValue(TChart1.Tools.Items(0).asDrawLine.Lines.Items(0).EndPos.X)
  Y1 = TChart1.Axis.Left.CalcYPosValue(TChart1.Tools.Items(0).asDrawLine.Lines.Items(0).EndPos.Y)
  
  Dim steep As Boolean
  steep = Math.Abs(Y1 - Y0) > Math.Abs(X1 - X0)
  If steep Then
    tmp = X0
    X0 = Y0
    Y0 = tmp
    
    tmp = X1
    X1 = Y1
    Y1 = tmp
  End If

  If X0 > X1 Then
    tmp = X0
    X0 = X1
    X1 = tmp
    
    tmp = Y0
    Y0 = Y1
    Y1 = tmp
  End If

  Dim deltax As Integer
  deltax = X1 - X0
  Dim deltay As Integer
  deltay = Math.Abs(Y1 - Y0)
  Dim ERR As Integer
  ERR = deltax \ 2
  Dim ystep As Integer
  Dim Y As Integer
  Y = Y0
  If Y0 < Y1 Then
    ystep = 1
  Else
    ystep = -1
  End If
  
  For X = X0 To X1
    If steep Then
      List1.AddItem Y & " " & X
    Else
      List1.AddItem X & " " & Y
    End If
    ERR = ERR - deltay
    If ERR < 0 Then
      Y = Y + ystep
      ERR = ERR + deltax
    End If
    
    For i = 0 To TChart1.Series(0).Count - 1
      tmp = TChart1.Series(0).Clicked(X, Y)
      If tmp > -1 Then
        TChart1.Series(0).PointColor(tmp) = vbRed
      End If
    Next i
  Next
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