Event
The VChart instance provides methods related to event monitoring, and developers can monitor events to meet business needs. In addition to basic dom events, the events provided on VChart also include component events, TTL events, etc.
Below is a simple monitor diagram click
Examples of events:
Event API
The registration and uninstallation methods of events are provided on the VChart instance:
- Register an event
- Uninstall event
Example:
event parameters
All events provide parameters of the following structure:
Event filtering
Event filtering configuration (parameter query: EventQuery
) is optional. If you need to specifically monitor events in a certain part of the chart, you can use the built-in query rules for configuration. Currently, we provide the following filtering rules:
source
, filter according to the event source, that is, listen to the events of the window or the chart itself.
level
, filter according to the event bubbling level. The bubbling order of events is: 'mark' -> 'model' -> 'chart' -> 'vchart'.
nodeName
, filter according to the picked graphics node name. Inside vchart, some component names will be built in for some components to facilitate user identification.
markName
, filter according to the name of mark primitive.
type
, only used in scenarios where level is 'mark' or 'model', is used to filter mark types or chart component element model types
id
, filter based on the id configured by the user on the spec for the chart component
filter
, when none of the above filtering configurations meet the needs, you can filter through a custom filtering function
In addition to the above configurations, query
also supports the following configurations:
Configuration | Type | Default | Description |
---|---|---|---|
consume | Boolean | false | Whether to stop event propagation |
throttle | Number | null | Duration of event throttling in ms, defaults to no throttling |
debounce | Number | null | Duration of event debouncing in ms, defaults to no debouncing |
Listen to component events through event filtering
Through the following event filtering rules, we can monitor the events of each component on the VChart example
However, it should be noted that not all components enable event interaction by default. For components that are turned off by default, users need to manually enable them on the spec corresponding to the component (such as enabling label event interaction: label: { interactive: true }
) , the following table lists the current component names of our VChart and how its events are turned on and off by default. You can refer to this table for specific use.
Component type | Whether to enable event support by default |
---|---|
axis | Yes |
dataZoom | Yes |
indicator | Yes |
legend | Yes |
mapLabel | Yes |
customMark | Yes |
title | Yes |
markLine | No |
markArea | No |
markPoint | No |
label | No |
totalLabel | No |
Monitor mark primitive events through event filtering
If you want to listen to the events of mark primitives, you can do it in two ways:
- Use
markName
to filter, such as:
- Use the
{ level: 'mark', type: 'bar' }
rule to filter, such as:
If you want to listen to the events of all primitives, you only need to declare level: 'mark'
, such as vchart.on('pointerdown', { level: 'mark'}, e => {})
The specific primitive types (corresponding to the types configured on the spec) are: 'point', 'line', 'area', 'bar', 'bar3d', 'boxPlot', 'outlier', 'circlePacking', 'dot ', 'funnel','funnel3d', 'link', 'pie', 'rose', 'pie3d', 'word', 'fillingWord', etc.
Event classification
base event
VChart supports the following basic events:
-
PointerEvent Pointer event
'pointerdown'
'pointerup'
'pointerupoutside'
: The graph is not triggered at the same time when the pointer is raised and pressed'pointertap'
: click event under pointerEvent'pointerover'
'pointermove'
'pointerenter'
: will not bubble'pointerleave'
: will not bubble'pointerout'
-
MouseEvent Mouse event
- Left button operation
'mousedown'
'mouseup'
'mouseupoutside'
: The graphics are not triggered at the same time when the mouse is raised and pressed
- Right click operation
'rightdown'
'rightup'
'rightupoutside'
: The graphics are not triggered at the same time when the mouse is raised and pressed
'click'
'dblclick'
'mousemove'
'mouseover'
'mouseout'
'mouseenter'
: will not bubble'mouseleave'
: will not bubble'wheel'
Roller event
- Left button operation
-
TouchEvent Touch event
'touchstart'
'touchend'
'touchendoutside'
'touchmove'
'touchcancel'
'tap'
: click event under touchEvent
-
Drag event
'dragstart'
'dragend'
'drag'
'dragenter'
'dragleave'
'dragover'
'drop'
-
Gesture event
'pan'
: translation'panstart'
: translation start'panend'
: end of translation'press'
: long press'pressup'
: long press release'pressend'
: long press end'pinch'
: zoom'pinchstart'
: zoom start'pinchend'
: zoom end'swipe'
: quick sweep
Note that gesture events are not enabled by default. There are two ways to enable them:
- Set
mode
in the rendering configuration to one of the following:'mobile-browser'
,'miniApp'
,'lynx'
,'wx'
,'harmony'
- Set
gestureConfig
in the rendering configuration to a non-empty object. For specific supported configurations, refer to vchart API configuration
combined event
dimensionHover
: Dimension hovering eventdimensionClick
: Dimension click event
Component event
DataZoom
'dataZoomChange'
Events fired after DataZoom filtering.
The event parameters are as follows:
ScrollBar
'scrollBarChange'
Event triggered after ScrollBar scrolls.
The event parameters are as follows:
Brush
'brushStart'
Brush The event triggered the box starts to select.
'brushChange'
Brush The event triggered after the box is selected.
'brushEnd'
Brush The event triggered the box selected has been finished.
'brushClear'
Brush The event triggered the box selected has been finished.
The event parameters are as follows:
Drill
The chart of the hierarchical data structure supports the drilling function and the events triggered after drilling. At present, the built-in charts in VChart support drilling: CirclePacking, Sunburst, and Treemap.
'drill'
Drill events triggered after drilling.
The event parameters are as follows:
Legend
Legend related events.
'legendItemClick'
discrete typeLegend click event
The event parameters are as follows:
'legendItemHover'
discrete typeLegend hover event
The event parameters are as follows:
'legendItemUnHover'
discrete typeLegend unhover event
The event parameters are as follows:
'legendFilter'
Continuous typeLegend Filter Event
The event parameters are as follows:
TTL event
-
'initialized'
Chart instance initialization completion event -
'rendered'
Triggered when the chart rendering method is called, indicating that the chart has already executed the rendering logic and will only be triggered once. -
'renderFinished'
Supported since1.2.0
version, , the event triggered every time the canvas is rendered, excluding the end of the animation -
'animationFinished'
Supported since1.2.0
version, event fired when the chart animation ends -
'layoutStart'
Layout start event -
'layoutEnd'
Layout end event -
'afterResize'
Triggered when the chart resized
The event parameters are as follows: