wpf-117310-controls-and-libraries-charts-suite-chart-control-print-and-export.md
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.
Call the ChartControlBase.PrintDirect method to use the default printer and page settings to print a chart.
private void onPrintButtonClick(object sender, RoutedEventArgs e) {
chartControl.PrintDirect();
}
Private Sub onPrintButtonClick(sender As Object, e As RoutedEventArgs)
chartControl.PrintDirect()
End Sub
You can use the ChartControlBase.Print method to change the print settings before printing.
private void onPrintButtonClick(object sender, RoutedEventArgs e) {
chartControl.Print();
}
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.
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 method | Description |
|---|---|
| ChartControlBase.ShowPrintPreview | Creates a document to be printed and invokes the Print Preview with the standard toolbar. |
| ChartControlBase.ShowPrintPreviewDialog | Creates a document to be printed and invokes the Print Preview with the standard toolbar as a modal window. |
| ChartControlBase.ShowRibbonPrintPreview | Creates a document to be printed and invokes the Print Preview with a Ribbon. |
| ChartControlBase.ShowRibbonPrintPreviewDialog | Creates 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 .
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 format | The appropriate method |
|---|---|
| ChartControlBase.ExportToPdf | |
| HTML | ChartControlBase.ExportToHtml |
| MHT | ChartControlBase.ExportToMht |
| RTF | ChartControlBase.ExportToRtf |
| XLS | ChartControlBase.ExportToXls |
| XLSX | ChartControlBase.ExportToXlsx |
| Image | ChartControlBase.ExportToImage |
| DOCX | ChartControlBase.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.
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.
<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
How to: Print a Chart and Show its Print Preview