---
title: "Chart Image Export"
enterprise: true
framework: vue
version: "36.1.0"
---

# Chart Image Export

This section shows how to export charts via the Chart Toolbar and Grid API.

## Export Charts via Chart Toolbar

Users can use the 'Download Chart' [Chart Menu](https://www.ag-grid.com/vue-data-grid/integrated-charts-menu/) item to download the rendered chart in the browser.

![Side Bar](https://www.ag-grid.com/_astro/chart-toolbar-download.RUoyY_JX.png)

Note that the downloaded chart image will be in a `PNG` format.

## Export Charts via Grid API

There are two ways to download the chart image using the Grid API as shown below:

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `getChartImageDataURL` | `Function` |  |  | Returns a base64-encoded image data URL for the referenced chartId. Module: [`IntegratedChartsModule`](https://www.ag-grid.com/vue-data-grid/modules/). |
| `downloadChart` | `Function` |  |  | Starts a browser-based image download for the referenced chartId. Module: [`IntegratedChartsModule`](https://www.ag-grid.com/vue-data-grid/modules/). |

You can use the `downloadChart(params)` API to download the chart image in the browser.

Alternatively for programmatic use-cases, the `getChartImageDataURL(params)` API returns the chart image as string (base64 encoded); this is ideal for persisting to a back-end, or opening/presenting the chart image statically.

The example below demonstrates how you can retrieve images rendered from the chart in multiple formats.

- Click **Download Chart Image (PNG)** to download a PNG format image via `getChartImageDataURL()`
- Click **Download Chart Image (JPG 800x500)** to download a custom size image via `downloadChart()`
- Click **Open Chart Image (JPG)** to open a JPEG format image in a new window via `getChartImageDataURL()`

#### Downloading Chart Image

```ts
import {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
import "./styles.css";
import { AgChartsEnterpriseModule } from "ag-charts-enterprise";
import {
  AgChartThemeOverrides,
  CellSelectionOptions,
  ChartCreatedEvent,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  CreateRangeChartParams,
  FirstDataRenderedEvent,
  GetChartImageDataUrlParams,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  NumberEditorModule,
  NumberFilterModule,
  TextEditorModule,
  TextFilterModule,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ContextMenuModule,
  IntegratedChartsModule,
  RowGroupingModule,
} from "ag-grid-enterprise";
import { getData } from "./data";
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  TextEditorModule,
  TextFilterModule,
  NumberEditorModule,
  NumberFilterModule,
  ClientSideRowModelModule,
  IntegratedChartsModule.with(AgChartsEnterpriseModule),
  ColumnMenuModule,
  ContextMenuModule,
  RowGroupingModule,
]);

let chartId: string | undefined;

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <div class="wrapper">
      <div id="buttons">
        <button v-on:click="downloadChartImage('image/png')">Download Chart Image (PNG)</button>
        <button v-on:click="downloadChart({ width: 800, height: 500 })">Download Chart Image (JPG 800x500)</button>
        <button v-on:click="openChartImage('image/jpeg')">Open Chart Image (JPG)</button>
      </div>
      <ag-grid-vue
        id="myGrid"
        style="width: 100%; height: 100%;"
        @grid-ready="onGridReady"
        :columnDefs="columnDefs"
        :defaultColDef="defaultColDef"
        :cellSelection="true"
        :popupParent="popupParent"
        :enableCharts="true"
        :chartThemeOverrides="chartThemeOverrides"
        :rowData="rowData"
        @first-data-rendered="onFirstDataRendered"
        @chart-created="onChartCreated"></ag-grid-vue>
        <div id="myChart" class="my-chart"></div>
      </div>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi | null>(null);
    const columnDefs = ref<ColDef[]>([
      { field: "country", chartDataType: "category" },
      { field: "sugar", chartDataType: "series" },
      { field: "fat", chartDataType: "series" },
      { field: "weight", chartDataType: "series" },
    ]);
    const defaultColDef = ref<ColDef>({
      editable: true,
      flex: 1,
      minWidth: 100,
      filter: true,
    });
    const popupParent = ref<HTMLElement | null>(document.body);
    const chartThemeOverrides = ref<AgChartThemeOverrides>({
      bar: {
        axes: {
          category: {
            label: {
              rotation: 335,
            },
          },
        },
      },
    });
    const rowData = ref<any[]>(null);

    function onFirstDataRendered(params: FirstDataRenderedEvent) {
      const createRangeChartParams: CreateRangeChartParams = {
        cellRange: {
          columns: ["country", "sugar", "fat", "weight"],
        },
        chartType: "groupedColumn",
        chartContainer: document.querySelector("#myChart") as any,
      };
      params.api.createRangeChart(createRangeChartParams);
    }
    function onChartCreated(event: ChartCreatedEvent) {
      chartId = event.chartId;
    }
    function downloadChart(dimensions: { width: number; height: number }) {
      if (!chartId) return;
      gridApi.value!.downloadChart({
        fileName: "resizedImage",
        fileFormat: "image/jpeg",
        chartId,
        dimensions,
      });
    }
    function downloadChartImage(fileFormat: string) {
      if (!chartId) return;
      const params: GetChartImageDataUrlParams = { fileFormat, chartId };
      const imageDataURL = gridApi.value!.getChartImageDataURL(params);
      if (imageDataURL) {
        const a = document.createElement("a");
        a.href = imageDataURL;
        a.download = "image";
        a.style.display = "none";
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
      }
    }
    function openChartImage(fileFormat: string) {
      if (!chartId) return;
      const params: GetChartImageDataUrlParams = { fileFormat, chartId };
      const imageDataURL = gridApi.value!.getChartImageDataURL(params);
      if (imageDataURL) {
        const image = new Image();
        image.src = imageDataURL;
        const w = window.open("")!;
        w.document.write(image.outerHTML);
        w.document.close();
      }
    }
    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

      getData().then((rowData) => params.api.setGridOption("rowData", rowData));
    };

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      popupParent,
      chartThemeOverrides,
      rowData,
      onGridReady,
      onFirstDataRendered,
      onChartCreated,
      downloadChart,
      downloadChartImage,
      openChartImage,
    };
  },
});

const app = createApp(VueExample);
app.mount("#app");
```

[Live example: Downloading Chart Image](https://www.ag-grid.com/examples/integrated-charts-api-downloading-image/downloading-chart-image/vue3)
