Files to look at:
The following example exports a chart to a PDF format. In this example, the form contains the Export to File and Export to Stream buttons that allow you to save the PDF document with the chart to a file or a stream.
Follow the steps below to implement this scenario:
-
Add a Chart Control object to the form. Make sure that the Chart Control Name is chartControl1 in the Visual Studio Properties window. For more information, see the following topic: How to: Add a Chart to a Windows Forms Application.
-
Create a Series object in the Form1_Load event handler. Use the ChartControl.Series.Add method to add this series to the chart.
-
Specify the ChartControl.DataSource, Series.ArgumentDataMember, and Series.ValueDataMembers properties to populate the chart with data. In this example, the GetSales method returns the chart data source.
-
Add two SimpleButtons to the form. Set the first button's Text property to Export to File and the second button's property to Export to Stream.
-
The Chart Control uses the DevExpress Printing Library to export a chart. To use this library, add references to the following assemblies to the project:
- DevExpress.XtraPrinting.19.2,
- DevExpress.Printing.v19.2.Core.
-
Handle the first button's Click event and use the ChartControl.IsPrintingAvailable property to check whether the chart can be exported. Call the ChartControl.ExportToPdf(String, PdfExportOptions) method to export the chart to a file. Pass the path to this file as the first parameter to the ExportToPdf method. Create an instance of the PdfExportOptions class to specify export settings. Set the PdfExportOptions.ConvertImagesToJpeg property to false to export the chart in the vector-based format. Pass the PdfExportOptions instance as the second parameter to the ExportToPdf method.
-
Handle the second button's Click event and use the ChartControl.IsPrintingAvailable property to check whether the chart can be exported. Call the ChartControl.ExportToPdf(System.IO.Stream) method to export the chart to a stream. This example uses FileStream, and you can open the file where the stream is saved to check the export result.
(you will be redirected to DevExpress.com to submit your response)