There are several events which are raised at different points in the lifecycle of a chart.
The ChartCreated event is raised whenever a chart is first created.
Properties available on the ChartCreated<TData = any> interface.
typechartCreated. chartIdapicolumnApiThis is raised any time that the data range used to render the chart from is changed, e.g. by using the range selection handle or by making changes in the Data tab of the configuration sidebar. This event contains a cellRange object that gives you information about the range, allowing you to recreate the chart.
Properties available on the ChartRangeSelectionChanged<TData = any> interface.
typechartRangeSelectionChanged. chartIdidchartId. cellRangecellRange: CellRangeParams;
interface CellRangeParams {
// Start row index
rowStartIndex: number | null;
// Pinned state of start row. Either 'top', 'bottom' or null
rowStartPinned?: string | null;
// End row index
rowEndIndex: number | null;
// Pinned state of end row. Either 'top', 'bottom' or null
rowEndPinned?: string | null;
// Starting column for range
columnStart?: string | Column;
// End column for range
columnEnd?: string | Column;
// Specify Columns to include instead of using `columnStart` and `columnEnd`
columns?: (string | Column)[];
}apicolumnApiFormatting changes made by users through the Format Panel will raise the ChartOptionsChanged event:
Properties available on the ChartOptionsChanged<TData = any> interface.
typechartOptionsChanged. chartIdchartTypechartType: ChartType;
type ChartType =
'column'
| 'groupedColumn'
| 'stackedColumn'
| 'normalizedColumn'
| 'bar'
| 'groupedBar'
| 'stackedBar'
| 'normalizedBar'
| 'line'
| 'scatter'
| 'bubble'
| 'pie'
| 'doughnut'
| 'area'
| 'stackedArea'
| 'normalizedArea'
| 'histogram'
| 'columnLineCombo'
| 'areaColumnCombo'
| 'customCombo'
chartThemeNamechartOptionsapicolumnApiHere the chartThemeName will be set to the name of the currently selected theme, which will be either
one of the Provided Themes or
a Custom Theme if used.
This is raised when a chart is destroyed.
Properties available on the ChartDestroyed<TData = any> interface.
typechartDestroyed. chartIdapicolumnApiThe following example demonstrates when the described events occur by writing to the console whenever they are triggered. Try the following:
Charts in the grid are produced by the Standalone Charts library, which is integrated directly into the grid for your convenience. In some advanced use cases, you may wish to access the chart instance that is produced by AG Charts, in order to interact with the chart directly.
The chart instance can be obtained from the chartRef using the getChartRef(chartId) API.
| Returns the ChartRef using the supplied chartId. |
Here is the implementation:
function onChartCreated(event) {
const chartRef = gridOptions.api.getChartRef(event.chartId);
const chart = chartRef.chart;
}Note in the snippet above, the chartId is obtained from the ChartCreated event which is supplied to the onChartCreated callback. The chartId is provided in all chart events.
The example below shows how the chart instance can be used, creating a subtitle and updating it dynamically as you change the range selection.
To learn about events see Standalone Chart Events.