I'm ripping my hair out over here so hopefully you guys can help. I need to do the following:
I need to display a graph, with one axes being dates, and the other standard deviations. The SD axis can be set to a max of +/- 2, 3, or 4 standard deviations. The 0, +2, and -2 grid lines need to be solid lines, and darker than the other lines. All of the other grid lines (+/- 1, +/- 3, and all .5 increments) need to be dotted. When all is said and done, I need to change the axis labels to explicitly show the value for each increment of the standard deviation (for instance, if the SD is 3, then I need to change the label for 1 to be 3, 2 to be 6, 3.5 to be 10.5, etc).
I have everything working except the darker lines at 0, and +/- 2 SD.
Using:
Set oDrawLineTool = oForm.tcGraph.Tools.Items(oForm.tcGraph.Tools.Add(tcDrawLine)).asDrawLine
With oDrawLineTool
.Pen.Style = psSolid
Call .AddLine(oForm.tcGraph.Axis.Bottom.MinXValue, -2, oForm.tcGraph.Axis.Bottom.MaxXValue, -2)
Call .AddLine(oForm.tcGraph.Axis.Bottom.MinXValue, 0, oForm.tcGraph.Axis.Bottom.MaxXValue, 0)
Call .AddLine(oForm.tcGraph.Axis.Bottom.MinXValue, 2, oForm.tcGraph.Axis.Bottom.MaxXValue, 2)
.EnableDraw = False
.EnableSelect = False
End With
I can draw the solid lines at the appropriate places. But when I try to add:
.pen.width = 2
It removes all of the newly drawn lines from the graph and I'm left with the old grid. And for some inexplicable reason, I can't get:
With TChart1
.Canvas.Brush.Style = bsSolid
.Canvas.Pen.Style = psSolid
.Canvas.Pen.Visible = True
.Canvas.Pen.Width = 2
Call .Canvas.MoveTo(TChart1.Axis.Bottom.MinXValue, 0)
Call .Canvas.LineTo(TChart1.Axis.Bottom.MaxXValue, 0)
End With
to do anything. I'm sure i'm doing something horribly wrong here. If anyone can point it out to me, I'd be greatly appreciative. All i need to do is draw dark lines at these 3 places. Any method of doing so is okay with me.
Need help, Drawing Grid Lines
Hi Gary,
which TeeChart Pro version are you using ?
I'm able to do this usign both methods (with the latest v6.05) and the following code :
which TeeChart Pro version are you using ?
I'm able to do this usign both methods (with the latest v6.05) and the following code :
Code: Select all
Private Sub Command1_Click()
With TChart1
.Tools.Add tcDrawLine
.Tools.Items(0).asDrawLine.AddLine TChart1.Axis.Bottom.MinXValue, 2, .Axis.Bottom.MaxXValue, 2
.Tools.Items(0).asDrawLine.AddLine TChart1.Axis.Bottom.MinXValue, 10, .Axis.Bottom.MaxXValue, 10
.Tools.Items(0).asDrawLine.EnableDraw = False
.Tools.Items(0).asDrawLine.EnableSelect = False
.Tools.Items(0).asDrawLine.Pen.Width = 2
End With
End Sub
Private Sub Form_Load()
With TChart1
.Aspect.View3D = False
.AddSeries scLine
For i = 0 To 10
.Series(0).AddXY i, Rnd * 20, "", clTeeColor
Next i
End With
End Sub
Private Sub TChart1_OnAfterDraw()
With TChart1
.Canvas.Brush.Style = bsSolid
.Canvas.Pen.Style = psSolid
.Canvas.Pen.Visible = True
.Canvas.Pen.Width = 2
.Canvas.MoveTo .Axis.Bottom.CalcXPosValue(0), .Axis.Left.CalcYPosValue(2)
.Canvas.LineTo .Axis.Bottom.CalcXPosValue(10), .Axis.Left.CalcYPosValue(2)
End With
End Sub
Pep Jorge
http://support.steema.com
http://support.steema.com
Bumping an old post because I'm still having problems with this. I'm using 6.0.0.3. I need to stay with this version for now due to client issues.
I'm using the following code to draw my lines:
Private Sub tcGraph_OnAfterDraw()
Dim oDrawLineTool As TeeChart.IDrawLineTool
Set oDrawLineTool = tcGraph.Tools.Items(tcGraph.Tools.Add(tcDrawLine)).asDrawLine
With oDrawLineTool
Call .AddLine(-2, DateValue("01/01/1980"), -2, DateValue("01/01/2050"))
Call .AddLine(0, DateValue("01/01/1980"), 0, DateValue("01/01/2050"))
Call .AddLine(2, DateValue("01/01/1980"), 2, DateValue("01/01/2050"))
.EnableDraw = False
.EnableSelect = False
End With
End Sub
The problem is that if there is only 1 point on the graph or there are multiple points with the same x value, the lines do not draw. I can get them to draw by changing the minimum and maximum of the bottom axis, but I don't want to have to do that in order to get the lines to show up. Is there some sort of refresh function that i can call to make them appear? or some other innocuous function that i can call which will do nothing but make the lines appear? Thanks in advance.
I'm using the following code to draw my lines:
Private Sub tcGraph_OnAfterDraw()
Dim oDrawLineTool As TeeChart.IDrawLineTool
Set oDrawLineTool = tcGraph.Tools.Items(tcGraph.Tools.Add(tcDrawLine)).asDrawLine
With oDrawLineTool
Call .AddLine(-2, DateValue("01/01/1980"), -2, DateValue("01/01/2050"))
Call .AddLine(0, DateValue("01/01/1980"), 0, DateValue("01/01/2050"))
Call .AddLine(2, DateValue("01/01/1980"), 2, DateValue("01/01/2050"))
.EnableDraw = False
.EnableSelect = False
End With
End Sub
The problem is that if there is only 1 point on the graph or there are multiple points with the same x value, the lines do not draw. I can get them to draw by changing the minimum and maximum of the bottom axis, but I don't want to have to do that in order to get the lines to show up. Is there some sort of refresh function that i can call to make them appear? or some other innocuous function that i can call which will do nothing but make the lines appear? Thanks in advance.
Hi Gary,
you can solve this by using the Axis.Position in that cases :
you can solve this by using the Axis.Position in that cases :
Code: Select all
Private Sub TChart1_OnAfterDraw()
With TChart1
.Canvas.MoveTo .Axis.Left.Position, .Axis.Left.CalcYPosValue(2)
.Canvas.LineTo .Axis.Right.Position, .Axis.Left.CalcYPosValue(2)
End With
End Sub
Pep Jorge
http://support.steema.com
http://support.steema.com