Print and Export in ASP.NET Core Chart component

18 Nov 20182 minutes to read

Print

The rendered chart can be printed directly from the browser by calling the public method print. You can pass array of ID of elements or element to this method. By default, it takes element of the chart.

Export

The rendered chart can be exported to JPEG, PNG, SVG, PDF, XLSX, or CSV format using the export method in chart. The input parameters for this method are type for format and fileName for result.

The optional parameters for this method are,

  • Orientation - either portrait or landscape mode during PDF export,
  • Controls - pass collections of controls for multiple export,
  • Width - width of chart export,
  • Height - height of chart export,
  • IsVertical - decides the chart export in vertical or horizontal direction,
  • Header - header for the exported chart,
  • Footer - footer for the exported chart, and
  • ExportToMultiplePages - decides to export multiple charts on separate pages for PDF export.

In the export method, specify the following parameters to add a header and footer text to the exported PDF document:

  • Header - Specify the text that should appear at the top of the exported PDF document.
  • Footer - Specify the text that should appear at the bottom of the exported PDF document.

The headers and footers can be positioned anywhere on the PDF page using the x and y properties.

Exporting charts into separate page during the PDF export

During PDF export, set the ExportToMultiplePage parameter to true to export each chart as a separate page.

Export with optional parameters

The rendered chart can be exported to specific orientation, width and height by passing it as optional parameters in the export method of chart.

Multiple chart export

You can export the multiple charts in single page by passing the multiple chart objects in the export method of chart. To export multiple charts in a single page, follow the given steps:

Initially, render more than one chart to export, and then add button to export the multiple charts. In button click, call the export method in charts, and then pass the multiple chart objects in the export method.

Exporting chart using base64 string

The chart can be exported as an image in the form of a base64 string by utilizing HTML canvas. This process involves rendering the chart onto a canvas element and then converting the canvas content to a base64 string.

Excel export

You can export the rendered chart data to Excel in either XLSX or CSV format. The ExcelProperties property in the BeforeExport event allows users to customize the exported Excel sheet by modifying row, column, and cell properties before the file is generated. You can customize row titles, column titles, cell values, as well as row and column widths.