legendHighlight
Previous
legendFilter
Next
poptip
Loading...
图例高亮元素。
import { Chart } from '@antv/g2';const chart = new Chart({container: 'container',});chart.interval().data(profit).axis('y', { labelFormatter: '~s' }).encode('x', 'month').encode('y', ['end', 'start']).encode('color',d.month === 'Total' ? 'Total' : d.profit > 0 ? 'Increase' : 'Decrease',).state('inactive', { opacity: 0.5 }).legend('color', {state: { inactive: { labelOpacity: 0.5, markerOpacity: 0.5 } },});chart.interaction('legendHighlight', true);chart.render();
chart.on('legend:highlight', (e) => {const { nativeEvent, data } = e;if (!nativeEvent) return;console.log(data);});chart.on('legend:unhighlight', (e) => {const { nativeEvent } = e;if (!nativeEvent) return;console.log('unhighlight');});
chart.emit('legend:highlight', {data: { channel: 'color', value: 'Increase' },});chart.emit('legend:unhighlight', {});