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

legend filter 状态保留 #5967

Closed
YY88Xu opened this issue Dec 21, 2023 · 4 comments
Closed

legend filter 状态保留 #5967

YY88Xu opened this issue Dec 21, 2023 · 4 comments

Comments

@YY88Xu
Copy link

YY88Xu commented Dec 21, 2023

问题描述

image 如图,比如在 5秒内触发了 legend 的 filter, 怎么在显示数字的时候能够保留筛选的 legend ,而不是全部刷新。

重现链接

No response

重现步骤

import { Chart } from '@antv/g2';

const chart = new Chart({ container: 'container' });

chart
  .interval()
  .data([
    { genre: 'Sports', sold: 0 },
    { genre: 'Strategy', sold: 115 },
    { genre: 'Action', sold: 120 },
    { genre: 'Shooter', sold: 350 },
    { genre: 'Other', sold: 150 },
  ])
  .encode('x', 'genre')
  .encode('y', 'sold')
  .encode('color', 'genre')
  .style('minHeight', 50);

chart.render();

setTimeout(()=>{
  chart.label({
    text: 'genre'
  })
  chart.render()
}, 5000)

预期行为

No response

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response

@pearmini
Copy link
Member

通过 chart.on 保存状态,通过 chart.emit 设置状态:https://g2.antv.antgroup.com/spec/interaction/legend-filter#%E6%A1%88%E4%BE%8B

@YY88Xu
Copy link
Author

YY88Xu commented Dec 22, 2023

不是这个意思,这个显示数值 label 是动态控制的。怎么让 label 显示的时候,保留已选 legend 的状态

@pearmini
Copy link
Member

监听 legendFilter 事件去保留当前的状态,然后 chart.render() 通过 chart.emit 去恢复状态。

@YY88Xu
Copy link
Author

YY88Xu commented Jan 6, 2024

监听 legendFilter 事件去保留当前的状态,然后 chart.render() 通过 chart.emit 去恢复状态。

@pearmini 可是这样中间有跳动,先有了数值,然后又去掉了 legend

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

No branches or pull requests

2 participants