Page 1 of 1

Easy question: 2 charts and text with 7.12 Steema Pro

Posted: Thu Feb 12, 2009 4:56 pm
by 9336407
I'm sure this is an 'old question' but I couldn't find it in the docs.

I'd like to use the 'chartPreviewer rather than create my own popup form, manually ad a TeePreview object and manually add text and two charts to it, though that might be a possible fall-back.

I have the 'new version' but for some stuff I'm still using 7.12. Is there a link to a quick sample of printing some text then two charts on the same page?
This crashes:
chartPreviewer1.PreviewPanel.Panels.Add(chart1);
chartPreviewer1.PreviewPanel.Panels.Add(chart2);
With chartSlitRepeat, Canvas, ChartRect do begin
... stuff to add lines of text
end;
chartPreviewer1.Execute;

The methods in the current version docs
chart1.getPrinter().beginPrint();... etc.
.. stuff to add 2nd chart
...endPrint();

Don't seem to be in this VCL version.

Posted: Fri Feb 13, 2009 12:49 pm
by yeray
Hi dunion,

The problem is that this component needs the form to be created when you add charts. So adding the charts at OnChartPreviewer1Show event it works fine here:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.PrintProportional := false;
  Chart2.PrintProportional := false;
  Chart3.PrintProportional := false;

  Chart1.PrintMargins := Rect(2,2,2,70);
  Chart2.PrintMargins := Rect(2,35,2,35);
  Chart3.PrintMargins := Rect(2,65,2,2);

  Chart1.Legend.Visible := false;
  Chart2.Legend.Visible := false;
  Chart3.Legend.Visible := false;

  ChartPreviewer1.Chart := Chart1;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ChartPreviewer1.Execute;
end;

procedure TForm1.ChartPreviewer1Show(Sender: TObject);
begin
  ChartPreviewer1.PreviewPanel.Panels.Add(Chart1);
  ChartPreviewer1.PreviewPanel.Panels.Add(Chart2);
  ChartPreviewer1.PreviewPanel.Panels.Add(Chart3);
end;

That works great. Adding extra labels on top of the charts?

Posted: Fri Feb 13, 2009 4:32 pm
by 9336407
What I wanted was something like hooking the OnAfterDraw and then using the chartPreviewer1.PreviewPanel's child drawing surface to write some extra 'title text' above both of the charts. Neither the chartPreviewer1.PreviewPanel.Canvas nor drawing on its Panels[0].Canvas does it.

Posted: Mon Feb 16, 2009 9:52 am
by yeray
Hi dunion,

In this case you should use the ChartPreviewer's OnAfterDraw event. Something like following:

Code: Select all

procedure TForm1.ChartPreviewer1AfterDraw(Sender: TObject);
begin
  ChartPreviewer1.PreviewPanel.canvas.TextOut(100,100,'ChartPreviewer AfterDraw');
end;

This doesn't work - I tried that

Posted: Tue Feb 17, 2009 3:38 pm
by 9336407
That only writes on the gray area around the chart, so it's not on the print area, and if the user re-sizes the chart it stays with the background not on the chart. What I need it to be is for example on the chart in such a way as it's a fixed position reletavie to the printout and will print out with the chart. So drawing it on the first chart-panel is OK, or moving both my chart penels to start 'down' and drawing on the surface behind them is ok, but I don't know what 'object' the panels are 'stuck on' that I can draw on. That's why I tried drawing on .Panel[0].canvas on this event, also. One thing I haven't tried is to take the On show and attach something explicitly to the panel's onafterdraw at this point and do the code there, that was my next thought.

Posted: Mon Feb 23, 2009 2:51 pm
by yeray
Hi dunion,

We've been doing some tests and finally I can suggest you two ways depending on where exactly you want to draw your text.

1) Draw your text in the chart area using ChartPreviewer. Note that in this way, you won't be able to draw your text in the paper zone where there isn't any chart but you still could set a big margin if you want. For example:

Code: Select all

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  Chart1.AutoRepaint := false;
  Chart1.MarginTop := 20;
  printing := true;
  ChartPreviewer1.Execute;
  Chart1.MarginTop := 4;
  Chart1.AutoRepaint := true;
  Chart1.Invalidate;;
  printing := false;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
  if printing then
  begin
    chart1.Canvas.Font.Height := -13;
    chart1.Canvas.TextOut(Chart1.Axes.Bottom.IStartPos,Chart1.Axes.Left.IStartPos,'AfterDraw Text');
  end;
end;
2) Create you own printing form, use a TeePreviewPanel instead of a PrintPreviewer to be shown in your custom form and print your chart using a metafile. This way, you could draw your text in the whole paper.
Please, take a look at this topic to see how you could print a metafile.