Page 1 of 1
Printing annotations
Posted: Tue Dec 28, 2004 5:44 pm
by 8438402
I find that if I add an annotoation to a chart and then print the chart the annotation is missing. The same happens when printing from the chartpreview. I also see the same problem when printing from the New Features Demo example. Can anyone suggest how to deal with this?
Mike Glazer
Posted: Tue Dec 28, 2004 10:50 pm
by Pep
Hi Mike,
the problem is all custom positioned object (Annotation, legend, text, series marks, lines, ...) 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.
The solutions:
+ To print, use the following code:
var tmpMeta: TMetaFile;
begin
tmpMeta := Chart1.TeeCreateMetafile(true,Chart1.ClientRect);
try
Printer.BeginDoc;
try
Printer.Canvas.StretchDraw(custom_printer_rect_region,tmpMeta);
finally
Printer.EndDoc;
end;
finally
tmpMeta.Free;
end;
end;
Basically you're creating a metafile with the same size as original chart. The consequence of this is custom positions will be valid for metafile as well. Then you use StretchDraw method to "paint" this image (with correct
custom items positions) directly onto Printer.Canvas.
+ If possible try using "axis" scale coordinate for Annotation position.
Basically, set (an example) custom item position to x=1.0, y=5.2 and then use Chart1.BottomAxis.CalcPosValue(x), Chart1.LeftAxis.CalcPosValue(y) to calculate current "screen" or "printer" canvas pixel position. Now you're defining Annotation position in axis scale and using CalcPosValue method to convert it to screen pixel coordinate. The advantage of this method is you can use TChartPreviewer and existing print methods.