Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(interaction): emit element select #5119

Merged
merged 1 commit into from
May 30, 2023
Merged

Conversation

pearmini
Copy link
Member

Element Select

element-select

chart.options({
  type: 'interval',
  transform: [
    { type: 'sortX', by: 'y', reverse: true, reducer: 'sum', slice: 6 },
    { type: 'dodgeX' },
  ],
  data: {
    type: 'fetch',
    value: 'data/stateages.csv',
  },
  encode: {
    x: 'state',
    y: 'population',
    color: 'age',
  },
  state: {
    selected: { fill: 'red' },
    unselected: { opacity: 0.6 },
  },
  interaction: {
    elementSelectByX: { delay: 0 },
    tooltip: false,
  },
});

获得数据

chart.on('element:select', (event) => {
  const { data, nativeEvent } = event;
  if (nativeEvent) console.log('element:select', data);
});

chart.on('element:unselect', (event) => {
  const { nativeEvent } = event;
  if (nativeEvent) console.log('reset');
});

触发交互

chart.emit('element:select', {
  data: { data: [{ population: 5038433 }, { population: 3983091 }] },
});

chart.emit('element:unselect', {});

@pearmini pearmini requested a review from hustcc May 30, 2023 02:47
@pearmini pearmini merged commit ea20755 into v5 May 30, 2023
@pearmini pearmini deleted the feat/emit-element-select branch May 30, 2023 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants