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

一个chart有两个类型相似的view, 分别采用同一个数据源产生的两个dataView作为数据, 在这种场景下如何实现用一个slider同时影响两个view? 是否有参考案例推荐?谢谢! #2331

Closed
BillSun2080 opened this issue Apr 18, 2020 · 4 comments
Assignees

Comments

@BillSun2080
Copy link

  • G2 Version: 4.0.7

  • Platform: Ant Design Pro

  • Mini Showcase(like screenshots):
    image

  • CodePen Link: N/A

@BillSun2080
Copy link
Author

附加另一个问题:chart/view 数据更新时,slider的数据如何保证更新?谢谢!

@hustcc
Copy link
Member

hustcc commented Jan 19, 2021

暂时没有一个 slider 控制多个 view 的能力。这种情况,可以外置自己写一个 slider,然后在 slider 交互的时候去过滤两个 view 的数据。

@belldandy4ever
Copy link

项目中同样的需求,我的解决方案是:

  1. 在最后一个view上,配置slider
  2. 监听配置slider的view的afterpaint事件,更新其他view

代码看起来像是这样:

   const chart = new Chart({
      container: "container",
      width: 800,
      height: 400,
    });

    const view1 = chart.createView({
      region: {
        start: { x: 0, y: 0 },
        end: { x: 1, y: 0.5 },
      },
    });
    view1.data(data);
    view1.interval().position("time*money");

    const viewLast = chart.createView({
      region: {
        start: { x: 0, y: 0.5 },
        end: { x: 1, y: 1 },
      },
    });
    viewLast.data(data);
    viewLast.interval().position("time*money");
    viewLast.option("slider", {});
    viewLast.on("afterpaint", () => {
      view1.changeData(viewLast.filteredData);
    });

    chart.render();

希望能帮助到你:)

@dcy0701
Copy link

dcy0701 commented Aug 7, 2023

基本同意 @belldandy4ever 的方案。
也可以通过 Apply 方法调用changeViewData方法达到同样目的。
源码里全是 this.view

chart.on(
      'slider:valuechanged',
      (ev) => {
        chart.getController('slider').changeViewData.apply(
          {
            view: mainView,
          },
          ev.event.value,
        );
      },
    );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants