antvis/G2

自定义图例 custom: true,自定义图例点击事件隐藏 #3583

bin-sun posted onGitHub

chart.legend({
  custom: true,
  items: [
    {
      name: '城市 1',
      id: 'city-1',
      marker: { symbol: 'triangle', style: { r: 4, fill: 'red' } },

    },
    {
      name: '城市 2',
      id: 'city-2',
    },
  ],
});

chart.on('legend-item:click', (ev) => {
  const { type, view, gEvent, data, x, y, clientX, clientY, target} = ev;
  console.log('data', data); // undefind
});

自定义图例事件data获取不到,如何通过自定义事件隐藏相对于图形呢?


在 target 中可以拿到对应触发点击事件的 shape,在这个 shape 中有对应图例项的数据,然后就可以去做过滤了。

posted by hustcc over 3 years ago

Fund this Issue

$0.00
Funded

Pull requests