State
Previous
zoomOut
Next
Overview
Loading...
State in G2 is mainly used to control the state style of mark. These states will be interactively triggered and the attributes are style attributes supported by @antv/g.
({type: 'interval',state: {active: { fill: 'red', stroke: 'blue', strokeWidth: 2 },inactive: { fill: '#aaa' },},});
// API// First waychart.interval().state('active', { fill: 'red', stroke: 'blue', strokeWidth: 2 }).state('inactive', { fill: '#aaa' });// Second waychart.interval().state({active: { fill: 'red', stroke: 'blue', strokeWidth: 2 },inactive: { fill: '#aaa' },});
There are currently 4 built-in states:
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',});chart.interval().data({type: 'fetch',value:'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv',}).encode('x', 'letter').encode('y', 'frequency').axis('y', { labelFormatter: '.0%' }).state('active', { fill: 'red' }).state('inactive', { fill: '#aaa' }).interaction('elementHighlight'); // Set up highlight interactionchart.render();
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',});chart.interval().data({type: 'fetch',value:'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv',}).encode('x', 'letter').encode('y', 'frequency').axis('y', { labelFormatter: '.0%' }).state('selected', { fill: 'red', stroke: 'blue', strokeWidth: 2 }).state('unselected', { fill: '#aaa' }).interaction('elementSelect'); // Set up selection interactionchart.render();