Back to Devexpress

How to: Print a Chart and Show Its Print Preview

windowsforms-3087-controls-and-libraries-chart-control-examples-producing-output-how-to-print-a-chart-and-show-its-print-preview.md

latest3.3 KB
Original Source

How to: Print a Chart and Show Its Print Preview

  • Nov 13, 2018
  • 2 minutes to read

The following example demonstrates how to print a ChartControl , or show its Print Preview. To do this, you should use either the ChartControl.Print or ChartControl.ShowPrintPreview methods.

Note

A chart can be printed and previewed only if the XtraPrinting Library is available. To verify that printing the chart is possible, use the ChartControl.IsPrintingAvailable property.

When printing a chart, the current print settings will be used to represent a chart. Note that you can access and change these settings via the ChartControl.OptionsPrint property. End-users manually select the printer settings by clicking the Customize toolbar button ( ) in a chart’s preview, and setting the required options in the Printable Component Editor.

csharp
using DevExpress.XtraCharts;
// ...

private void ShowChartPreview(ChartControl chart) {
    // Check whether the ChartControl can be previewed.
    if (!chart.IsPrintingAvailable) {
        MessageBox.Show("The 'DevExpress.XtraPrinting.v7.2.dll' is not found", "Error");
        return;
    }
    // Open the Preview window.
    chart.ShowPrintPreview();
}

private void PrintChart(ChartControl chart) {
    // Check whether the ChartControl can be printed.
    if (!chart.IsPrintingAvailable) {
        MessageBox.Show("The 'DevExpress.XtraPrinting.v7.2.dll' is not found", "Error");
        return;
    }
    // Print.
    chart.Print();
}
vb
Imports DevExpress.XtraCharts
' ...

Sub ShowChartPreview(ByVal chart As ChartControl)
   ' Check whether the ChartControl can be previewed.
   If Not chart.IsPrintingAvailable Then
      MessageBox.Show("The 'DevExpress.XtraPrinting.v7.2.dll' is not found", "Error")
      Return
   End If

   ' Opens the Preview window.
   chart.ShowPrintPreview()
End Sub

Sub PrintChart(ByVal chart As ChartControl)
   ' Check whether the ChartControl can be printed.
   If Not chart.IsPrintingAvailable Then
      MessageBox.Show("The 'DevExpress.XtraPrinting.v7.2.dll' is not found", "Error")
      Return
   End If

   ' Print.
   chart.Print()
End Sub

The image below shows the print preview of a ChartControl.

Note

If you want to be able to customize different printing options when printing a chart, you need to print it via the PrintableComponentLink component. For more information on using this component, refer to the How to: Use the PrintableComponentLink to Print DevExpress Controls tutorial.