Print and Export
- 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.
- Immediately Print a Chart
- Show the Print Dialog
- Show the Chart’s Print Preview
- Export a Chart
- Specify the Chart Print Options
Note
You should add a reference to the DevExpress.Xpf.Printing.24.1 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.
private void onPrintButtonClick(object sender, RoutedEventArgs e) {
chartControl.PrintDirect();
}
Show the Print Dialog
You can use the ChartControlBase.Print method to change the print settings before printing.
private void onPrintButtonClick(object sender, RoutedEventArgs e) {
chartControl.Print();
}
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 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 .
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 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.
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.
<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.