Angular Data GridChart EventsEnterprise
There are several events which are raised at different points in the lifecycle of a chart.
ChartCreated
The ChartCreated
event is raised whenever a chart is first created.
Properties available on the ChartCreated<TData = any, TContext = any>
interface.
typeTypestring | Will always be chartCreated . |
chart | Id of the created chart. This can later be used to reference the chart via api methods. |
apiTypeGridApi | The grid api. |
column | The column api. |
contextTypeTContext | Application context as set on gridOptions.context . |
ChartRangeSelectionChanged
This 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, TContext = any>
interface.
typeTypestring | Will always be chartRangeSelectionChanged . |
chart | Id of the effected chart. |
idTypestring | Same as chartId . |
cell | New cellRange selected. |
apiTypeGridApi | The grid api. |
column | The column api. |
contextTypeTContext | Application context as set on gridOptions.context . |
ChartOptionsChanged
Formatting changes made by users through the Format Panel will raise the ChartOptionsChanged
event:
Properties available on the ChartOptionsChanged<TData = any, TContext = any>
interface.
typeTypestring | Will always be chartOptionsChanged . |
chart | Id of the effected chart. |
chart | ChartType |
chart | Chart theme name of currently selected theme. |
chart | Chart options. |
apiTypeGridApi | The grid api. |
column | The column api. |
contextTypeTContext | Application context as set on gridOptions.context . |
Here 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.
ChartDestroyed
This is raised when a chart is destroyed.
Properties available on the ChartDestroyed<TData = any, TContext = any>
interface.
typeTypestring | Will always be chartDestroyed . |
chart | Id of the effected chart. |
apiTypeGridApi | The grid api. |
column | The column api. |
contextTypeTContext | Application context as set on gridOptions.context . |
Example: Chart Events
The following example demonstrates when the described events occur by writing to the console whenever they are triggered. Try the following:
-
Create a chart from selection, for example, select a few cells in the "Month" and "Sunshine" columns and right-click to "Chart Range" as a "Line" chart. Notice that a "Created chart with ID id-xxxxxxxxxxxxx" message has been logged to the console.
-
Shrink or expand the selection by a few cells to see the "Changed range selection of chart with ID id-xxxxxxxxxxxx" logged.
-
Click the Chart Tool Panels Button inside the chart dialog to show chart settings and switch to a column chart. Notice that a "Changed options of chart with ID id-xxxxxxxxxxxxx" message has been logged to the console.
-
Close the chart dialog to see the "Destroyed chart with ID id-xxxxxxxxxxx" message logged.
Event Driven Chart Updates
The following example updates the chart when ChartRangeSelectionChanged
events are raised. Note that charts can be
updated using the following Grid API method:
Try changing the chart cell range in the grid and notice the subtitle is updated with chart range info.
Standalone Chart Events
It is possible to subscribe to the Standalone Charts Events using the theme based configuration
via the chartThemeOverrides
grid option:
<ag-grid-angular
[chartThemeOverrides]="chartThemeOverrides"
/* other grid options ... */>
</ag-grid-angular>
this.chartThemeOverrides = {
common: {
legend: {
listeners: {
legendItemClick: (e) => console.log('legendItemClick', e)
}
},
listeners: {
seriesNodeClick: (e) => console.log('seriesNodeClick', e)
}
}
;
Note that chartThemeOverrides
maps to the overrides
Theme property.
The example below demonstrates Standalone Charts Events subscription:
- Click on the bars in the series and observe that the
seriesNodeClick
listener emits a console message. - Click on a legend item and observe that the
legendItemClick
listener emits a console message.
Next Up
Continue to the next section to learn about: Time Series.