---
product: "AG Grid"
title: "Chart Container"
description: "This section shows how to specify an alternative chart container to the default grid-provided popup window."
enterprise: true
framework: javascript
version: "36.2.0"
related:
    - title: "Overview"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts/"
    - title: "Install Integrated Charts"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts-installation/"
    - title: "User Created Charts"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts-user-created/"
    - title: "Application Created Charts"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts-application-created/"
    - title: "Chart Types"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts-chart-types/"
    - title: "Chart Menu"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts-menu/"
    - title: "Chart Tool Panels"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts-chart-tool-panels/"
    - title: "Customisation"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts-customisation/"
    - title: "Chart Events"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts-events/"
    - title: "Time Series"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts-time-series/"
    - title: "Save / Restore Charts"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts-api-save-restore-charts/"
    - title: "Chart Image Export"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/integrated-charts-api-downloading-image/"
llms: "https://www.ag-grid.com/archive/36.2.0/llms.txt"
---

# Chart Container

This section shows how to specify an alternative chart container to the default grid-provided popup window.

Displaying the generated chart within the grid-provided popup window will suit most needs. However, you may wish to display the chart in a different location. For example, your application may already have popup windows, and you wish to use the same library for consistency.

## Specifying Chart Container

To provide an alternative container for popup windows use the grid callback `createChartContainer(chartRef)`.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `createChartContainer` | `CreateChartContainer` |  |  |  |

The callback is called each time the user elects to create a chart via the grid UI. The callback is provided with a `ChartRef` implementation:

Properties available on the `ChartRef` interface.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `chartId` | `string` |  |  |  |
| `chart` | `any` |  |  |  |
| `chartElement` | `HTMLElement` |  |  |  |
| `destroyChart` | `Function` |  |  |  |
| `focusChart` | `Function` |  |  |  |
| `setMaximized` | `Function` |  |  |  |

The example below demonstrates the `createChartContainer(chartRef)` callback. The example does not use an alternative popup window, but instead places the charts into the DOM below the grid. This crude approach is on purpose to minimise the complexity of the example and focus on just the callback and the interactions of the grid.

> **Note**
>
> When providing an element to display your chart, it is important to always set the `popupParent` to be `document.body`. This will allow floating elements within the chart's menus to be positioned correctly.

From the example below, the following can be noted:

- Select a range of numbers (medal columns) and create a chart from the context menu.
- The chart appears below the grid rather than in a popup window. This is because the `createChartContainer(chartRef)` is implemented.
- Each chart is displayed alongside a 'Destroy' button. The logic behind the destroy button calls `destroyChart()` to destroy the chart instance.

#### Provided Container

```ts
import { AgChartsEnterpriseModule } from "ag-charts-enterprise";
import {
  ChartRef,
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ContextMenuModule,
  IntegratedChartsModule,
  RowGroupingModule,
} from "ag-grid-enterprise";

if (process.env.NODE_ENV !== "production") {
  // Enable extended validations only for development
  enableDevValidations();
}

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

let gridApi: GridApi;

const gridOptions: GridOptions = {
  columnDefs: [
    { field: "athlete", width: 150, chartDataType: "category" },
    { field: "gold", chartDataType: "series" },
    { field: "silver", chartDataType: "series" },
    { field: "bronze", chartDataType: "series" },
    { field: "total", chartDataType: "series" },
  ],
  defaultColDef: { flex: 1 },
  cellSelection: true,
  enableCharts: true,
  popupParent: document.body,
  createChartContainer,
};

function updateChart(chartRef: ChartRef | undefined) {
  const eParent = document.querySelector("#chartParent") as HTMLElement;
  eParent.innerHTML = ""; // Clear existing content
  const placeHolder = `<div class="chart-placeholder">Chart will be displayed here.</div>`;

  if (chartRef) {
    const chartWrapperHTML = `
    <div class="chart-wrapper">
      <div class="chart-wrapper-top">
        <h2 class="chart-wrapper-title">Chart created ${new Date().toLocaleString()}</h2>
        <button class="chart-wrapper-close">Destroy Chart</button>
      </div>
      <div class="chart-wrapper-body"></div>
    </div>
  `;
    eParent.insertAdjacentHTML("beforeend", chartWrapperHTML);
    const eChartWrapper = eParent.lastElementChild as HTMLElement;

    eChartWrapper
      .querySelector(".chart-wrapper-body")!
      .appendChild(chartRef.chartElement);
    eChartWrapper
      .querySelector(".chart-wrapper-close")!
      .addEventListener("click", () => {
        chartRef.destroyChart();
        eParent.innerHTML = placeHolder;
      });
  } else {
    eParent.innerHTML = placeHolder;
  }
}

// Function for creating the chart container
function createChartContainer(chartRef: ChartRef): void {
  updateChart(chartRef);
}

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);
updateChart(undefined);

fetch("https://www.ag-grid.com/example-assets/wide-spread-of-sports.json")
  .then((response) => response.json())
  .then(function (data) {
    gridApi!.setGridOption("rowData", data);
  });
```

[Live example: Provided Container](https://www.ag-grid.com/archive/36.2.0/examples/integrated-charts-container/provided-container/typescript/)
