Back to Devexpress

Print and Export

wpf-117310-controls-and-libraries-charts-suite-chart-control-print-and-export.md

latest7.5 KB
Original Source

Print and Export

  • May 28, 2021
  • 3 minutes to read

The Chart control allows you to print a chart and export it to different file formats using the chart’s API, the system’s print dialog or the Print Preview form.

This topic describes how to print and export a chart and configure its print options.

Note

You should add a reference to the DevExpress.Xpf.Printing.25.2 assembly to preview, print, and export a chart using the DXPrinting Library.

Immediately Print a Chart

Call the ChartControlBase.PrintDirect method to use the default printer and page settings to print a chart.

csharp
private void onPrintButtonClick(object sender, RoutedEventArgs e) {
        chartControl.PrintDirect();
}
vb
Private Sub onPrintButtonClick(sender As Object, e As RoutedEventArgs)
    chartControl.PrintDirect()
End Sub

Show the Print Dialog

You can use the ChartControlBase.Print method to change the print settings before printing.

csharp
private void onPrintButtonClick(object sender, RoutedEventArgs e) {
        chartControl.Print();
}
vb
Private Sub onPrintButtonClick(sender As Object, e As RoutedEventArgs)
    chartControl.Print()
End Sub

The code above invokes the standard print dialog. Specify the required settings and click the OK button to print a chart.

Show the Chart’s Print Preview

End users can print/export a chart and customize printing/exporting settings using the Print Preview. The following methods invoke the Print Preview dialog:

The appropriate methodDescription
ChartControlBase.ShowPrintPreviewCreates a document to be printed and invokes the Print Preview with the standard toolbar.
ChartControlBase.ShowPrintPreviewDialogCreates a document to be printed and invokes the Print Preview with the standard toolbar as a modal window.
ChartControlBase.ShowRibbonPrintPreviewCreates a document to be printed and invokes the Print Preview with a Ribbon.
ChartControlBase.ShowRibbonPrintPreviewDialogCreates a document to be printed and invokes the Print Preview with a Ribbon as a modal window.

The Print group on the Print Preview’s Ribbon contains buttons that allow you to print a chart and configure print settings. To print a chart, click the Print… item.

The Export group on the Print Preview’s Ribbon comprises buttons that allow you to export a chart and then save it to a file on the disk or attach the file to an e-mail. To export a chart, click the Export… and select the desired file format.

Note

The images above illustrate the Ribbon Print Preview .

Export a Chart

You can use API methods to convert a chart to a specific format. The following table lists the file formats and their corresponding export methods:

The exporting formatThe appropriate method
PDFChartControlBase.ExportToPdf
HTMLChartControlBase.ExportToHtml
MHTChartControlBase.ExportToMht
RTFChartControlBase.ExportToRtf
XLSChartControlBase.ExportToXls
XLSXChartControlBase.ExportToXlsx
ImageChartControlBase.ExportToImage
DOCXChartControlBase.ExportToDocx

Note

You should specify a Chart Control’s size using its Width and Height properties when you are exporting a chart that is not added to the Window’s Content. Otherwise, the exported document is empty.

Specify the Chart Print Options

The ChartControlBase.PrintOptions property provides access to the chart’s print options. The options specify the printed/exported chart’s parameters. Use the ChartPrintOptions.SizeMode property to define how the printed/exported chart should be resized on a page.

The code below demonstrates how to fit the chart’s size to the printed page’s size.

xaml
<dxc:ChartControl Name="chartControl">
        <dxc:ChartControl.PrintOptions>
                <dxc:ChartPrintOptions SizeMode="Stretch"/>
        </dxc:ChartControl.PrintOptions>
        <!--...-->
</dxc:ChartControl>

You can also use a PrintSizeMode value as the ChartControlBase.PrintDirect, ChartControlBase.Print and ExportTo~ (for example, ChartControlBase.ExportToPdf, ChartControlBase.ExportToImage, etc.) method parameter.

See Also

Printing-Exporting

Document Preview

How to: Print a Chart and Show its Print Preview

How to: Export a Chart to HTML and MHT

How to: Export a Chart to PDF