Printing annotations

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Mike G
Newbie
Newbie
Posts: 4
Joined: Fri Nov 15, 2002 12:00 am
Location: Oxford

Printing annotations

Post by Mike G » Tue Dec 28, 2004 5:44 pm

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

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue Dec 28, 2004 10:50 pm

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.

Post Reply