This section explains how to listen and respond to various chart and series events.
Fired when this series' node is clicked. Depending on the type of series, a node can mean a bar or a pie sector, or a marker, such as a line or an area series marker. A node is typically associated with a single element from the data
or series[].data
array, unless the node represents an aggregation of values (e.g. histogram series bins).
Every nodeClick
event contains:
series
the node belongs todatum
datum
that were used to fetch the values represented by the clicked nodeThis example shows how the nodeClick
event listener can be used to listen to column clicks. Notice the following:
This example shows how the nodeClick
event listener can be used to toggle each node's selected
state in combination with a series[].marker.formatter
:
Fired when this series' node is double clicked.
Every nodeDoubleClick
event contains:
series
the node belongs todatum
datum
that were used to fetch the values represented by the clicked nodeThis example shows how the nodeDoubleClick
event listener can be used to listen to column double clicks.
The legendItemClick
event can be used to listen to legend item clicks. A listener can be configured via legend.listeners.legendItemClick
.
The event object passed to the listener includes:
seriesId
of the series associated with the legend itemitemId
, usually the yKey
value for cartesian seriesenabled
, whether the legend item is currently enabled or notFor example, to show an alert message with the legendItemClick
event contents when a legend item is clicked, the following listener can be configured:
legend: {
listeners: {
legendItemClick: ({
seriesId,
itemId,
enabled,
}: AgChartLegendClickEvent) => {
window.alert(
`seriesId: ${seriesId}, itemId: ${itemId}, enabled: ${enabled}`
)
}
}
}
This example demonstrates:
legendItemClick
event contents.legendItemDoubleClick
event contents.The click
and doubleClick
events are fired when any part of the chart is clicked or double clicked, respectively. When a user double clicks the click
event will be fired on the first click, then both the click
and doubleClick
will be fired on the second click.
These events may be prevented by other clickable parts of the chart, such as series nodes and legend items.
This example demonstrates:
The seriesNodeClick
event can be used to listen to nodeClick
events of all series at once.
The contents of the event object passed to the listener will depend on the type of series the clicked node belongs to.
This example demonstrates:
By default, the nodeClick
event is only triggered when the user clicks exactly on a node. You can use the nodeClickRange
option to instead define a range at which the event is triggered. This can be set to one of three values: 'nearest'
, 'exact'
or a number as a distance in pixels.
This example shows the three different types of interaction range that are possible.
'exact'
(default) will trigger the event if the user clicks exactly on a node'nearest'
will trigger the event for whichever node is nearest on the whole chartAll series event options have similar interface contracts. See the series-specific documentation for variations.
Properties available on the AgSeriesListeners<DatumType>
interface.
Properties available on the AgBaseChartListeners
interface.