首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >同步2个图表与g2plot的交互

同步2个图表与g2plot的交互
EN

Stack Overflow用户
提问于 2020-06-23 05:37:59
回答 1查看 86关注 0票数 0

我正在使用G2plot (https://github.com/antvis/G2Plot),当我在一个图表上悬停时,我想同步我的两个图表?作为基准进行比较。我希望保持悬停效果(背景)相同,并在两个图表上显示工具提示。。你有什么想法吗?

我找到了这个例子:https://g2plot.antv.vision/en/examples/advanced/connection,但它对我没有帮助。

EN

回答 1

Stack Overflow用户

发布于 2021-03-26 09:47:30

尝试更新到G2Plot 2.x。它支持自定义交互。

一个使用MultiView plot的迷人的example,否则您可以使用2个plot并自定义交互,如下所示:

代码语言:javascript
复制
import { Column } from '@antv/g2plot';

const data = [
  {
    type: '家具家电',
    sales: 38,
  },
  {
    type: '粮油副食',
    sales: 52,
  },
  {
    type: '生鲜水果',
    sales: 61,
  },
  {
    type: '美容洗护',
    sales: 145,
  },
  {
    type: '母婴用品',
    sales: 48,
  },
  {
    type: '进口食品',
    sales: 38,
  },
  {
    type: '食品饮料',
    sales: 38,
  },
  {
    type: '家庭清洁',
    sales: 38,
  },
];

const div = document.getElementById('container');
const div1 = document.createElement('div')
div1.id = 'container1'
div.parentNode.append(div1)

const columnPlot = new Column('container', {
  data,
  autoFit: false,
  height: 200,
  xField: 'type',
  yField: 'sales',
});

columnPlot.render();

const columnPlot1 = new Column('container1', {
  data,
  autoFit: false,
  height: 200,
  xField: 'type',
  yField: 'sales',
});

columnPlot1.render();

columnPlot.on('tooltip:show', (e) => {
  const { title } = e.data;
  const elements = columnPlot1.chart.geometries[0].elements.filter(ele => ele.getModel().data['type'] === title)
  elements.forEach(element => {
    const box = element.shape.getCanvasBBox();
    columnPlot1.chart.showTooltip({ x: box.minX + box.width / 2, y: box.minY + box.height / 2 });
  })
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62523893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档