ChartControl.ExportToImage(String, ImageFormat) Method
Creates an image file in the specified format from the current chart and outputs it to the specified path.
Namespace: DevExpress.XtraCharts
Assembly: DevExpress.XtraCharts.v18.2.UI.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
filePath | String | A String containing the full path to where the image file will be created. |
format | ImageFormat | A ImageFormat value representing the format in which the chart is exported. |
Remarks
If a file under the specified file path exists, the new file replaces it.
To show the standard Print dialog, use the ChartControl.Print method. The dialog allows end-users to print the chart, select the printer (if required), specify the range of pages to print, the number of copies, etc.
To display the DevExpress Print Preview use one of the following methods.
Method | Description |
---|---|
ChartControl.ShowPrintPreview | Creates the print document and displays the Print Preview of the document. |
ChartControl.ShowRibbonPrintPreview | Creates the print document and displays the Print Preview with the Ribbon toolbar of the document. |
To export the chart, use the appropriate ExportTo~ method (e.g., ChartControl.ExportToHtml, ChartControl.ExportToPdf, etc.)
Important
Note that, exporting to raster and vector images is implemented by the Chart and does not require any library.
The chart can be previewed, printed and exported to other formats only if the Printing library is available. Make sure you add a reference to the DevExpress.XtraPrinting.v18.2 assembly.
Also note that chart export to PDF requires the DevExpress.Pdf.Core library to be available.
Example
The following example demonstrates how to use the ExportToImage method to create an image from a chart control. The first method returns the image in the specified format, while the second writes the chart’s image in the specified format to the specified path.
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using DevExpress.XtraCharts;
// ...
private Image GetChartImage(ChartControl chart, ImageFormat format) {
// Create an image.
Image image = null;
// Create an image of the chart.
using(MemoryStream s = new MemoryStream()) {
chart.ExportToImage(s, format);
image = Image.FromStream(s);
}
// Return the image.
return image;
}
private void SaveChartImageToFile(ChartControl chart, ImageFormat format, String fileName) {
// Create an image in the specified format from the chart
// and save it to the specified path.
chart.ExportToImage(fileName, format);
}