Contents page 
  Previous | Next 
 

Tutorial 14 - Printing Charts


Contents

Standard Printing

Simple Print command
Print Orientation
Print Preview
Print Detail
Greyscale printing

Extended Printing methods

PrintPartial
Printing multiple page Charts
Printing several Charts on one page
Mixing printed Chart output with other print output


Standard Printing

TeeChart Pro offers standard print methods to print the Onscreen Chart 'as is' to the Printer.

Simple Print command

To print a Chart use the PrintChart method. This will print the chart as it appears onscreen.

Example

TChart1.Printer.PrintChart

Print Orientation

The PrintPortrait and PrintLandscape methods allow you to print those orientations even if they are not defined as the default. The default orientation will take effect again after the prnt is complete. Default Orientation can be changed using the Orientation property. The Orientation method will not print for you. You must run Print afterwards.

Example

With TChart1.Printer
  .Orientation = poLandscape
  .PrintChart
End With

Print Preview

The PrintPreview window will show you how the Chart will appear when printed. You may modify print parameters in the Print Preview window. To call PrintPreview run:

TChart1.Printer.ShowPreview

Alternatively use the configurable PrintPreview of the TeePreviewer component (see Tutorial 17).


Print Detail

Print Detail is not to be confused with print resolution which is defined with your Printer setup in Windows' Print management. Print Detail defines the amount of TeeChart detail to be included in the printed Chart, its Axis scale detail, Gridline frequency, etc. The value range is a percentage from 0-100%.

Example

'this will use screen resolution
TChart1.Printer.Detail = 0 
'this will use more printer resolution 
TChart1.Printer.Detail = 100 

Greyscale printing

When printing to Greyscale printers you should take care that the colours of the Chart are easily distinguishable when translated to shades of grey. To help, you could add Brush styles to the Chart Series to more easily distinguish Series when printed.


Extended Printing methods

PrintPartial

Use PrintPartial to send a Chart to the printer without ejecting the page. PrintPartial should be used with BeginDoc and EndDoc to start and end the Printer job. More than one Chart can be sent to the same page/printer job and user custom input can be included too.

Example

'Prints 2 Charts to a page
Private Sub Command2_Click()
  With TChart1.Printer
    .Orientation = poLandscape
    .BeginDoc
    .PrintPartial 0, 0, .PageWidth / 2, .PageHeight
  End With
  With TChart2.Printer
    .PrintPartial .PageWidth / 2, 0, .PageWidth, .PageHeight
    .EndDoc
  End With
End Sub

Printing multiple page Charts

For information about printing multipage Charts (where MaxPointsPerPage is less than the total point quantity) please see the Chart paging tutorial.


Print previewing several Charts on one page

The Print Preview panel now accepts more than one Chart (or TeePanel). Chart positions are controlled setting the PrintMargins property. Use the TeePreviewPanel1.Panels collection to manage the Charts on the Preview page.

  { change margins }
  Chart1.PrintProportional:=False;
  Chart2.PrintProportional:=False;

  Chart1.PrintMargins:=Rect(2,2,60,60);
  Chart2.PrintMargins:=Rect(60,60,2,2);

  { add to preview }
  TeePreviewPanel1.Panels.Add(Chart1);
  TeePreviewPanel1.Panels.Add(Chart1);

Only one Chart may be mousedrag moved on the Previewer at one viewing so you must disable the 1st Chart from view to enable drag repositioning of the 2nd Chart. The TeeChart demo project includes a page with the following code:

  With TeePreviewPanel1 do
  begin
    Panels.Clear;
    if CheckBox1.Checked then Panels.Add(FirstChart);
    if CheckBox2.Checked then Panels.Add(SecondChart);
    Repaint;
  end;

By selecting one or another of the 2 Checkboxes (when both are showing only the first Chart is moveable) you may reposition both the Charts on the page via mousedrag.

Mixing printed Chart output with other print output

Use the PrintPartialHandle method to mix TeeChart print output with non Chart printer output.

The following example takes the text from 2 Text boxes and prints them on a page with a TeeChart.

Private Sub Command1_Click()
Dim HWidth, HHeight, ChartLeft, ChartTop, ChartRight, ChartBottom ' Declare variables.
    On Error GoTo ErrorHandler  ' Set up error handler.
    Printer.Orientation = vbPRORPortrait
    'Scale & position text.
    HWidth = Printer.TextWidth(Text1.Text) / 2 ' Get half width.
    HHeight = Printer.TextHeight(Text1.Text) / 2   ' Get half height.
    Printer.CurrentX = Printer.ScaleWidth / 3 - HWidth
    Printer.CurrentY = Printer.ScaleHeight / 3 - HHeight
    Printer.Print Text1.Text ' Print 1st Text box
    With TChart1.Printer
      'Chart needs to orientated separately
      .Orientation = poPortrait
      'Set the chart position
      ChartLeft = .PageWidth / 3
      ChartTop = (.PageHeight / 3) + 30
      ChartRight = (.PageWidth / 3) * 2
      ChartBottom = (2 * (.PageHeight / 3)) - HHeight - 10
      'Attach the Chart output to the open print job
      .PrintPartialHandle Printer.hDC, ChartLeft, _
            ChartTop, ChartRight, ChartBottom
    End With
    Printer.CurrentY = 2 * Printer.ScaleHeight / 3 - HHeight
    Printer.CurrentX = Printer.ScaleWidth / 3 - HWidth
    Printer.Print Text2.Text ' Print 2nd Text box
    Printer.EndDoc  ' Printing is finished.
    Exit Sub
    
ErrorHandler:
    MsgBox "There was a problem printing to your printer."
    Exit Sub
End Sub




© 1998- Steema Software SL. All rights reserved.