I'm using TeeChart Pro ActiveX versione 5 and VB6.
On a Gannt chart I'm showing MarksTip in order to display some information about Gannt segment.
User is allowed to move MarksTip (I used DragMarks tool). The problem is that when I print the chart, moved MarksTips are not printed in the correct position even if in print preview are displayed correctly.
Does anybody can suggest me any way to solve this problem ?
Best regards
Luigi
MarksTip and chart printing
Hi Luigi,
the problem is all custom positioned object (legend, text, series marks) use screen pixels coordinates. While this is fine for screen it does not work for printer. Why ? The reason for this is if you print, TeeChart will internally change chart size (so that it fits in specified printer.Canvas region). The result is Chart size will change but the custom positioned items "positions" on printer canvas will remain the same (in screen pixel coordinates). This will result in custom items being drawn at wrong place.
To print custom-positioned objects out to the right positions you need to:
1) Position objects relative to other TeeChart objects
2) Create an EXE for test printing in VB
3) Draw your objects to the TeeChart Canvas using TeeChart's
On##Draw##() events , e.g.
Example :
the problem is all custom positioned object (legend, text, series marks) use screen pixels coordinates. While this is fine for screen it does not work for printer. Why ? The reason for this is if you print, TeeChart will internally change chart size (so that it fits in specified printer.Canvas region). The result is Chart size will change but the custom positioned items "positions" on printer canvas will remain the same (in screen pixel coordinates). This will result in custom items being drawn at wrong place.
To print custom-positioned objects out to the right positions you need to:
1) Position objects relative to other TeeChart objects
2) Create an EXE for test printing in VB
3) Draw your objects to the TeeChart Canvas using TeeChart's
On##Draw##() events , e.g.
Example :
Code: Select all
Private Sub Command1_Click()
TChart1.Printer.ShowPreview
End Sub
Private Sub Form_Load()
With TChart1
.Aspect.View3D = False
.AddSeries scBar
.Series(0).FillSampleValues 10
.Tools.Add tcAnnotate
.Tools.Items(0).asAnnotation.Shape.CustomPosition = True
.Environment.InternalRepaint
End With
End Sub
Private Sub TChart1_OnBeforeDrawSeries()
With TChart1
.Canvas.ClipRectangle .Axis.Left.Position, 0, .Axis.Right.Position,
.Axis.Bottom.Position
End With
End Sub
Private Sub TChart1_OnSeriesBeforeDrawValues(ByVal SeriesIndex As Long)
With TChart1
.Tools.Items(0).asAnnotation.Shape.Top = .Axis.Top.Position
.Tools.Items(0).asAnnotation.Shape.Left =
.Series(0).CalcXPosValue(5)
.Tools.Items(0).asAnnotation.Text = "Custom Position"
End With
End Sub
Pep Jorge
http://support.steema.com
http://support.steema.com
Hi Luigi,
Solutions:
1. Re-position the image relative to other TeeChart objects - unfortunately
this has to be done in events which are fired after the TChart has been
drawn.
2. Export the TeeChart to one of the Metafile formats and then use the
Windows API to print this metafile out to the printer.
Yes, using the same techniques.Is it possible to do what you suggest me also with marks tips ?
Solutions:
1. Re-position the image relative to other TeeChart objects - unfortunately
this has to be done in events which are fired after the TChart has been
drawn.
2. Export the TeeChart to one of the Metafile formats and then use the
Windows API to print this metafile out to the printer.
Pep Jorge
http://support.steema.com
http://support.steema.com
Hi Jose
I tried your suggestion about positioning marks tips relative to other objects in the chart. What happens is that on the screen the mark tips is correctly handled (if I scroll, marks tip is correctly scrolled with the chart); when I print out the chart marks tip I changed position of are printed shifted away from the the correct position that I can see on the screen.
What I'm doing wrong ?
The following is the code I use in the OnSeriesBeforeDrawValues event handler of the chart. Variables x, y, fromX, fromY ... are variables I use to store correct position of the mark tip (and his arrow) in the chart.
Thank you very much.
Private Sub TChart1_OnSeriesBeforeDrawValues(ByVal SeriesIndex As Long)
TChart1.Series(0).Marks.Positions.Position(0).Custom = True
TChart1.Series(0).Marks.Positions.Position(0).LeftTop.x = TChart1.Series(0).CalcXPosValue(x)
TChart1.Series(0).Marks.Positions.Position(0).LeftTop.y = TChart1.Series(0).CalcYPosValue(y)
TChart1.Series(0).Marks.Positions.Position(0).ArrowFrom.x = TChart1.Series(0).CalcXPosValue(fromX)
TChart1.Series(0).Marks.Positions.Position(0).ArrowFrom.y=TChart1.Series(0).CalcYPosValue(fromY)
TChart1.Series(0).Marks.Positions.Position(0).ArrowTo.x = TChart1.Series(0).CalcXPosValue(toX)
TChart1.Series(0).Marks.Positions.Position(0).ArrowTo.y = TChart1.Series(0).CalcYPosValue(toY)
End Sub
I tried your suggestion about positioning marks tips relative to other objects in the chart. What happens is that on the screen the mark tips is correctly handled (if I scroll, marks tip is correctly scrolled with the chart); when I print out the chart marks tip I changed position of are printed shifted away from the the correct position that I can see on the screen.
What I'm doing wrong ?
The following is the code I use in the OnSeriesBeforeDrawValues event handler of the chart. Variables x, y, fromX, fromY ... are variables I use to store correct position of the mark tip (and his arrow) in the chart.
Thank you very much.
Private Sub TChart1_OnSeriesBeforeDrawValues(ByVal SeriesIndex As Long)
TChart1.Series(0).Marks.Positions.Position(0).Custom = True
TChart1.Series(0).Marks.Positions.Position(0).LeftTop.x = TChart1.Series(0).CalcXPosValue(x)
TChart1.Series(0).Marks.Positions.Position(0).LeftTop.y = TChart1.Series(0).CalcYPosValue(y)
TChart1.Series(0).Marks.Positions.Position(0).ArrowFrom.x = TChart1.Series(0).CalcXPosValue(fromX)
TChart1.Series(0).Marks.Positions.Position(0).ArrowFrom.y=TChart1.Series(0).CalcYPosValue(fromY)
TChart1.Series(0).Marks.Positions.Position(0).ArrowTo.x = TChart1.Series(0).CalcXPosValue(toX)
TChart1.Series(0).Marks.Positions.Position(0).ArrowTo.y = TChart1.Series(0).CalcYPosValue(toY)
End Sub