Skip to content

带文本的气泡图点重叠时只显示单个标签(文本) #5035

Answered by hustcc
smilecoc asked this question in Q&A
Discussion options

You must be logged in to vote

在 5.x 中可以自动处理掉,如下代码:

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

const chart = new Chart({
  container: 'container',
  theme: 'classic',
  autoFit: true,
});

chart
  .point()
  .data({
    type: 'fetch',
    value: 'https://gw.alipayobjects.com/os/antvdemo/assets/data/bubble.json',
  })
  .encode('x', 'GDP')
  .encode('y', 'LifeExpectancy')
  .encode('size', 'Population')
  .encode('color', 'continent')
  .encode('shape', 'point')
  .label({
    text: 'LifeExpectancy',
    transform: [{
      type: 'overlapHide',  // 👈🏻,碰撞的时候,隐藏
    }]
  })
  .scale('size', { type: 'log', range: [4, 20] })
  .style('fillOpacity', 0.3)
  .style('lineWidth', 1);

chart.render();

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by hustcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3618 on May 16, 2023 09:13.