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 slider filter #5114

Merged
merged 1 commit into from
May 29, 2023
Merged

feat(interaction): emit slider filter #5114

merged 1 commit into from
May 29, 2023

Conversation

pearmini
Copy link
Member

@pearmini pearmini commented May 29, 2023

SliderFilter

May-29-2023 15-19-19

const chart = new Chart({
  theme: 'classic',
  container: 'container',
  paddingLeft: 80,
  paddingBottom: 120,
});

chart.options({
  type: 'interval',
  data: [
    { date: '2001-01', value: 100 },
    { date: '2001-02', value: 400 },
    { date: '2001-03', value: 500 },
    { date: '2001-04', value: 600 },
    { date: '2001-05', value: 300 },
    { date: '2001-06', value: 600 },
    { date: '2001-07', value: 300 },
    { date: '2001-08', value: 600 },
    { date: '2001-09', value: 109 },
    { date: '2001-10', value: 100 },
    { date: '2001-11', value: 102 },
    { date: '2001-12', value: 103 },
    { date: '2002-01', value: 102 },
    { date: '2002-02', value: 101 },
    { date: '2002-03', value: 200 },
    { date: '2002-04', value: 500 },
    { date: '2002-05', value: 100 },
    { date: '2002-06', value: 100 },
    { date: '2002-07', value: 102 },
    { date: '2002-08', value: 109 },
  ],
  encode: { x: 'date', y: 'value' },
  axis: { x: { size: 100, style: { labelTransform: 'rotate(90)' } } },
  slider: { x: {}, y: { labelFormatter: (d) => +d.toFixed(1) + '' } },
});

chart.render();

触发事件

chart.emit('sliderX:filter', {
  data: { selection: [['2001-01', '2001-03'], undefined] },
});

chart.emit('sliderY:filter', {
  data: { selection: [undefined, [50, 550]] },
});

监听数据

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

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

@pearmini pearmini merged commit 32ac0f6 into v5 May 29, 2023
3 checks passed
@pearmini pearmini deleted the feat/emit-slider-filter branch May 29, 2023 07:46
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.

None yet

2 participants