Skip to content
+

Charts - Export

Let users export a chart as an image or in PDF format.

Charts can be exported as images, as SVG files, or as PDFs using the browser's native print dialog. The exporting feature is available for the following charts:

  • LineChartPro
  • BarChartPro
  • ScatterChartPro
  • PieChartPro
  • Heatmap
  • FunnelChart
  • RadarChartPro
  • SankeyChart
  • CandlestickChart

Implementing exporting

Default toolbar

To enable exporting from the chart's toolbar, pass the showToolbar prop to the chart component. The toolbar then renders a button that opens a menu with the export options.

Inflation rate in France, Germany and the UK, 1960-2024

  • Germany
  • United Kingdom
  • France
MUI X Missing license key
Source: World Bank
Press Enter to start editing

Custom toolbar

See the Toolbar documentation for more information on how to create a custom toolbar.

Image exporting

You must install rasterizehtml to enable image exporting:

npm install rasterizehtml

Export options

Export behavior can be modified with print, image export, and SVG export options. These options can be passed to the built-in toolbar using slotProps.toolbar, and are then automatically displayed.

You can customize their respective behaviors by passing an options object to slotProps.toolbar, or to the export trigger itself if you're using a custom toolbar:

// Default toolbar:
<BarChartPro slotProps={{ toolbar: { printOptions, imageExportOptions, svgExportOptions } }} />

// Custom trigger:
<ChartsToolbarImageExportTrigger options={imageExportOptions} />
<ChartsToolbarPrintExportTrigger options={printExportOptions} />
<ChartsToolbarSvgExportTrigger options={svgExportOptions} />

Export formats

To disable the print export, set the disableToolbarButton property to true on printOptions. The SVG export can be disabled the same way through svgExportOptions.

You can customize image export formats by providing an array of objects to the imageExportOptions property. These objects must contain the type property which specifies the image format.

In the example below, you can toggle which export formats are available to the user. The name of the exported file has been customized to resemble the chart's title.

Population vs GDP Per Capita (USD), 2019

  • Europe
  • Asia
  • North America
  • South America
  • Africa
  • Oceania
MUI X Missing license key
Source: World Bank
const filename = 'Population_vs_GDP_Per_Capita_USD_2019';
          
<ScatterChartPro
  // ...
  slotProps={{
    toolbar: {
      printOptions: { fileName },
      imageExportOptions: [
        { type: "image/png" , filename }
      ]
    },
  }}
/>

Add custom styles before exporting

To add custom styles or modify the chart's appearance before exporting, use the onBeforeExport callback.

For image and PDF export, onBeforeExport receives the iframe the chart is rendered into before the export process starts. SVG export serializes an SVG document, so its onBeforeExport receives the <svg> element to be exported instead.

For example, you can add the title and caption to the exported chart as shown below:

Inflation rate in France, Germany and the UK, 1960-2024

  • Germany
  • United Kingdom
  • France
MUI X Missing license key
Source: World Bank
Press Enter to start editing

Hide elements from export

Mark any element with the data-hide-on-export attribute to exclude it from image and print exports. The attribute works on any HTML or SVG element in the chart tree.

  • Sales
  • Returns
MUI X Missing license key

To hide an internal MUI X Charts component (such as the legend) that you do not render directly, forward the attribute through slotProps:

<BarChartPro slotProps={{ legend: { 'data-hide-on-export': true } as any }} />

Copy styles

The styles of the page the chart belongs to are copied to the export iframe by default. You can disable this behavior by setting the copyStyles property to false in the export options.

<BarChartPro slotProps={{ toolbar: { printOptions: { copyStyles: false } } }} />

Exporting composed charts

MUI X Charts may be self-contained or composed of various subcomponents. See Composition for more details on implementing the latter type.

ChartsWrapper is considered the root element of a chart for exporting purposes, and all descendants are included in the export.

To use a custom wrapper instead, you must set the reference to the root element with the useChartRootRef() hook as shown below:

Composite Chart
  • Bar
  • Line
MUI X Missing license key

Content Security Policy (CSP)

If your application uses a Content Security Policy (CSP), you might need to adjust it for exporting to work correctly. See the dedicated document on CSP for more details.

apiRef

The apiRef prop exposes the exportAsPrint() method that can be used to open the browser's print dialog. The print dialog lets you print the chart or save it as a PDF, as well as configure other settings.

  • Series A
  • Series B
MUI X Missing license key

Export as image

The apiRef prop also exposes the exportAsImage() method to export the chart as an image. The function accepts an options object with the type property which specifies the image format. The available formats are:

  • image/png and image/jpeg which can both be used across all supported platforms
  • image/webp which is only supported in some browsers

If the format is not supported by the browser, exportAsImage() falls back to image/png.

For lossy formats such as image/jpeg and image/webp, the options object accepts the quality property which sets a numerical value between 0 and 1. The default is 0.9.

You can also pass a pixelRatio to control the scale at which the chart is rasterized. Higher values produce sharper images at the cost of a larger file size. When omitted, the export uses the larger of window.devicePixelRatio and 2, guaranteeing a minimum 2x resolution on standard-DPI displays without regressing higher-DPI exports.

apiRef.current?.exportAsImage({ pixelRatio: 3 });
  • Series A
  • Series B
MUI X Missing license key

Only applicable to lossy formats.

Press Enter to start editing

Export as SVG

The apiRef prop also exposes the exportAsSvg() method to export the chart as a standalone SVG file. Unlike image export, this requires no extra dependency.

The output is vector-based, so it stays crisp at any size and remains editable in design tools such as Figma. Series rendered to a canvas (for example, the WebGL renderer) cannot be vectorized and are embedded as a raster image inside the SVG, while the rest of the chart (axes, labels, legend) stays vector.

apiRef.current?.exportAsSvg({ fileName: 'my-chart' });
  • Series A
  • Series B
MUI X Missing license key

API

See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.