Method Signatures
Description
Theon() method binds event handlers to listen for chart events such as mouse interactions, data selections, and custom actions. The off() method removes previously bound event handlers.
These methods enable interactive features and allow you to respond to user interactions with the chart.
Parameters
on() Parameters
The name of the event to listen for. Event names are case-insensitive and automatically converted to lowercase. See Event Types for available events.
The callback function to execute when the event is triggered. The function receives an event parameter object with details about the event.
The context (
this value) for the handler function. If not provided, the handler will be called with undefined as the context.off() Parameters
The name of the event to remove handlers from.
The specific handler function to remove. If not provided, all handlers for the event will be removed.
Return Value
Both methods return the ECharts instance, allowing for method chaining.Event Types
Mouse Events
These events are triggered by mouse interactions with chart elements:click- Mouse clickdblclick- Mouse double-clickmousedown- Mouse button pressedmouseup- Mouse button releasedmouseover- Mouse enters an elementmouseout- Mouse leaves an elementmousemove- Mouse moves over an elementglobalout- Mouse leaves the entire chart areacontextmenu- Right-click context menu
Chart Lifecycle Events
rendered- Chart rendering is complete (fires after each frame)finished- All rendering and animations are complete
Action Events
These events are triggered bydispatchAction() calls:
highlight- Data item is highlighteddownplay- Data item highlight is removedselect- Data item is selectedunselect- Data item is unselectedlegendselectchanged- Legend selection state changeslegendselected- Legend item is selectedlegendunselected- Legend item is unselecteddatazoom- Data zoom range changesdatarangeselected- Visual map range changestimelinechanged- Timeline current index changestimelineplaychanged- Timeline play state changesrestore- Chart is restored to initial statedataviewchanged- Data view is modifiedmagictypechanged- Magic type (chart type) is changedgeoselectchanged- Map selection state changesgeoselected- Map region is selectedgeounselected- Map region is unselectedpieselectchanged- Pie chart selection state changespieselected- Pie chart sector is selectedpieunselected- Pie chart sector is unselectedmapselectchanged- Map selection state changesmapselected- Map region is selectedmapunselected- Map region is unselectedaxisareaselected- Parallel axis area is selectedbrush- Brush selection is madebrushEnd- Brush selection endsbrushselected- Brush selection changesglobalcursortaken- Global cursor is taken for brushrendered- Rendering is completefinished- All updates are finished
Event Object Properties
When an event is triggered, the handler receives an event object with the following common properties:The event type name
The original ZRender event object (for mouse events)
The component type that triggered the event (e.g., ‘series’, ‘xAxis’, ‘legend’)
The index of the component in its type
The series type (e.g., ‘line’, ‘bar’, ‘pie’) for series events
The index of the series
The name of the series
The name of the data item
The index of the data item in the series
The data value of the triggered item
The data type (e.g., ‘node’, ‘edge’ for graph)
The value of the data item
The color of the triggered item
Examples
Basic Click Handler
Mouse Hover Effects
Data Selection Tracking
Legend Interaction
Data Zoom Handler
Rendering Complete Callback
Using Context
Removing Event Handlers
Conditional Event Handling
Debounced Event Handler
Event Chaining
Cross-Chart Communication
Important Notes
Event names are automatically converted to lowercase.
chart.on('Click', handler) is equivalent to chart.on('click', handler).Mouse events are only triggered for elements that have been rendered and are visible in the chart. Events won’t fire for data points outside the current zoom range or hidden by legend interactions.
Common Patterns
Drill-Down Navigation
Custom Tooltip
Analytics Tracking
Related Methods
- dispatchAction() - Trigger chart actions programmatically
- setOption() - Configure chart options
Source Reference
Implementation:src/core/echarts.ts:2707-2708
The on() and off() methods use the internal createRegisterEventWithLowercaseECharts function which wraps the base Eventful class methods and automatically converts event names to lowercase.