echarts 页面内多图表实例联动场景下,如何关闭个别属性联动,例如关闭tooltip联动,其他行为联动保持正常

rmbxnbpk  于 2022-12-31  发布在  Echarts
关注(0)|答案(9)|浏览(732)

Version

4.9.0

Steps to reproduce

  • 初始化10个图表,groupId设置为相同的,并执行echarts.connect(groupId)
  • 鼠标浮动到某个图表上,默认显示所有图表的tooltip

What is expected?

多实例联动时,取消tooltip联动,即浮动到某个图表上时,只显示改图表的tooltip,其他图表的关闭掉,同时不影响如缩放联动等其他功能

What is actually happening?

想确认有没有方法关闭tooltip的联动效果

0g0grzrc

0g0grzrc1#

Hi! We've received your issue and please be patient to get responded. 🎉
The average response time is expected to be within one day for weekdays.

In the meanwhile, please make sure that you have posted enough image to demo your request. You may also check out the API and chart option to get the answer.

If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to dev@echarts.apache.org . Please attach the issue link if it's a technical question.

If you are interested in the project, you may also subscribe our mailing list .

Have a nice day! 🍵

czfnxgou

czfnxgou3#

https://github.com/apache/incubator-echarts/blob/master/test/connect-manually.html 可以参考这个例子,手动触发 connect

但是这个不是很方便,我还是赞同楼主的说法,联动的时候有没有办法设置哪些事件支持联动

nc1teljy

nc1teljy4#

https://github.com/apache/incubator-echarts/blob/master/test/connect-manually.html 可以参考这个例子,手动触发 connect

或者能否支持这样传入escapeConnect来避免被联动?
chartInstance.dispatchAction({ type: 'legendSelect', name: 'test', escapeConnect: true });

ttcibm8c

ttcibm8c5#

讲一下我最后的解决办法,仅供参考,非必要不建议改源码

图表联动,本质是某一图表触发action时,遍历当前group内的图表,dispatch对应的action,

解决的思路为,在遍历group,触发action前,判断 eventType 是否需要联动,不需要则不触发action

解决方法:

  • 图表配置 options 内增加要排除的联动属性 disabledConnectEventTypes , string []
  • 在这个方法内,判断如果是不需要联动的属性,不触发action
each(eventActionMap, function (actionType, eventType) {
      chart._messageCenter.on(eventType, function (event) {
        var options = chart._model.option;
        // 过滤不需要联动的actionType
        var disabledConnectEventTypes = _.get(chart, '_model.option.customConf.disabledConnectEventTypes', []);
        if (disabledConnectEventTypes.includes(eventType)) return
        // 原有逻辑 ....
      });
    });
wydwbb8l

wydwbb8l6#

讲一下我最后的解决办法,仅供参考,非必要不建议改源码

图表联动,本质是某一图表触发action时,遍历当前group内的图表,dispatch对应的action,

解决的思路为,在遍历group,触发action前,判断 eventType 是否需要联动,不需要则不触发action

解决方法:

  • 图表配置 options 内增加要排除的联动属性 disabledConnectEventTypes , string []
  • 在这个方法内,判断如果是不需要联动的属性,不触发action
each(eventActionMap, function (actionType, eventType) {
      chart._messageCenter.on(eventType, function (event) {
        var options = chart._model.option;
        // 过滤不需要联动的actionType
        var disabledConnectEventTypes = _.get(chart, '_model.option.customConf.disabledConnectEventTypes', []);
        if (disabledConnectEventTypes.includes(eventType)) return
        // 原有逻辑 ....
      });
    });

你这个是修改源码了么

p3rjfoxz

p3rjfoxz7#

讲一下我最后的解决办法,仅供参考,非必要不建议改源码
图表联动,本质是某一图表触发action时,遍历当前group内的图表,dispatch对应的action,
解决的思路为,在遍历group,触发action前,判断 eventType 是否需要联动,不需要则不触发action
解决方法:

  • 图表配置 options 内增加要排除的联动属性 disabledConnectEventTypes , string []
  • 在这个方法内,判断如果是不需要联动的属性,不触发action
each(eventActionMap, function (actionType, eventType) {
      chart._messageCenter.on(eventType, function (event) {
        var options = chart._model.option;
        // 过滤不需要联动的actionType
        var disabledConnectEventTypes = _.get(chart, '_model.option.customConf.disabledConnectEventTypes', []);
        if (disabledConnectEventTypes.includes(eventType)) return
        // 原有逻辑 ....
      });
    });

你这个是修改源码了么

是的,不建议改源码,我们是项目里有多处需要改的,就一并改了

dfuffjeb

dfuffjeb8#

讲一下我最后的解决办法,仅供参考,非必要不建议改源码
图表联动,本质是某一图表触发action时,遍历当前group内的图表,dispatch对应的action,
解决的思路为,在遍历group,触发action前,判断 eventType 是否需要联动,不需要则不触发action
解决方法:

  • 图表配置 options 内增加要排除的联动属性 disabledConnectEventTypes , string []
  • 在这个方法内,判断如果是不需要联动的属性,不触发action
each(eventActionMap, function (actionType, eventType) {
      chart._messageCenter.on(eventType, function (event) {
        var options = chart._model.option;
        // 过滤不需要联动的actionType
        var disabledConnectEventTypes = _.get(chart, '_model.option.customConf.disabledConnectEventTypes', []);
        if (disabledConnectEventTypes.includes(eventType)) return
        // 原有逻辑 ....
      });
    });

你这个是修改源码了么

是的,不建议改源码,我们是项目里有多处需要改的,就一并改了

我看了下echarts源码找到了一种新的解决办法,就是使用batch方式,这样可以使用到escapeConnect属性

chartInstance.dispatchAction({
  type: 'legendUnSelect',
  escapeConnect: true,
  batch: [
    {
      name: key,
      selected: legendsSelected,
    },
  ],
});
c90pui9n

c90pui9n9#

可以试试这个

// 手动处理图表联动
this[this.state.chartsList[0]].echarts.util.each(chartInstances, (fromChart) => {
  this[this.state.chartsList[0]].echarts.util.each(chartInstances, (toChart) => {
    if (fromChart === toChart) {
      return;
    }
    // tooltip 联动
    fromChart.on('updateAxisPointer', (params) => {
      toChart.dispatchAction(
          toChart.makeActionFromEvent(params),
          true
      );
    });
    // toolbox 缩放按钮操作联动
    fromChart.on('globalcursortaken', (params) => {
      toChart.dispatchAction(
          toChart.makeActionFromEvent(params),
          true
      );
    });
    // 图表缩放联动
    fromChart.on('dataZoom', (params) => {
      const dictData = { type: 'dataZoom' };
      if (params.batch[0].startValue !== undefined) {
        dictData.startValue = params.batch[0].startValue;
        dictData.endValue = params.batch[0].endValue;
      } else {
        dictData.start = params.batch[0].start;
        dictData.end = params.batch[0].end;
      }
      toChart.dispatchAction(dictData, true);
    });
    // toolbox 重置按钮操作联动
    fromChart.on('restore', (params) => {
      toChart.dispatchAction(
          toChart.makeActionFromEvent(params),
          true
      );
    });
  });
});

相关问题