From Steema Software Reference Wiki
Jump to: navigation, search


Contents page
Previous | Next

Tutorial 14 - Printing Charts

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.



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.


With TChart1.Printer
  .Orientation = poLandscape
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:


Alternatively use the configurable PrintPreview of the TeePreviewer component (see [Tutorial17.htm 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%.


'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


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.


'Prints 2 Charts to a page
Private Sub Command2_Click()
  With TChart1.Printer
    .Orientation = poLandscape
    .PrintPartial 0, 0, .PageWidth / 2, .PageHeight
  End With
  With TChart2.Printer
    .PrintPartial .PageWidth / 2, 0, .PageWidth, .PageHeight
  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 }


  { add to preview }

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
    if CheckBox1.Checked then Panels.Add(FirstChart);
    if CheckBox2.Checked then Panels.Add(SecondChart);

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

    MsgBox "There was a problem printing to your printer."
    Exit Sub
End Sub



© 1998-2019 Steema Software SL. All rights reserved.