Page 1 of 1

drawing on canvas

Posted: Wed Nov 24, 2004 2:13 pm
by 9524492
Hi
Is there an easy way to draw lines and arcs on the graph area only?
I have a problem because custom drawings on the canvas and series do not share the same area, the canvas is bigger.
Suppose this situation

Private Sub Form_Load()
X = Array(1, 2, 3, 4, 5)
Y = Array(2, 3, 1, 5, 8)
With TChart1
.ClearChart
.AddSeries scLine
.Aspect.View3d = False
.Series(0).AddArray 5, Y, X
.Axis.Left.Automatic = False
.Axis.Bottom.Automatic = False
.Axis.Bottom.Minimum = 0
.Axis.Bottom.Maximum = 10
.Axis.Left.Minimum = 0
.Axis.Left.Maximum = 10
End With
end sub

Private Sub TChart1_OnBeforeDrawAxes()
With TChart1
posx = .Axis.Bottom.CalcXPosValue(-2)
posy = .Axis.Left.CalcYPosValue(-2)
.Canvas.MoveTo posx, posy
posx = .Axis.Bottom.CalcXPosValue(2)
posy = .Axis.Left.CalcYPosValue(2)
.Canvas.LineTo posx, posy
End With
End Sub

the line is partly drawn outside the axis' region, and partly within the axis region together with the series.
Is there an easy way to display drawings only in the series region and not outside axises?
Any help would be very much appreciated, it would avoid me a great deal of work.

Thanks in advance
Ivan

Posted: Thu Nov 25, 2004 12:45 pm
by Pep
Hi Ivan,

yes, you can use the ClipRectangle method :

Code: Select all

Private Sub TChart1_OnBeforeDrawSeries()
With TChart1
  .Canvas.ClipRectangle .Axis.Left.Position, 0, .Axis.Right.Position, .Axis.Bottom.Position
  .Canvas.Pen.Color = vbBlack
    posx1 = .Axis.Bottom.CalcXPosValue(-2)
    posy1 = .Axis.Left.CalcYPosValue(-2)
    .Canvas.MoveTo posx1, posy1
    posx = .Axis.Bottom.CalcXPosValue(2)
    posy = .Axis.Left.CalcYPosValue(2)
    .Canvas.LineTo posx, posy
End With
End Sub

Drawing on canvas

Posted: Thu Nov 25, 2004 1:58 pm
by 9524492
Great!

Thank you very much, I was getting crazy by calculating intersections of arcs and lines with the 4 axis... :?

Thank you
Ivan

P.S. Have you had any luck with the isometric bug?

Posted: Thu Nov 25, 2004 2:25 pm
by Pep
Hi Ivan,

I'm working on some bugs now, hope to found a solution soon.