antvis/G2

散点图设置legend后,tooltip的提示不变 #4957

KuduroJS posted onGitHub

14EA2A6C-E8FD-4d70-9B5B-55B71ED99A19

如图,预期"male"显示"test-legend"

用例代码:

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/basement_prod/6b4aa721-b039-49b9-99d8-540b3f87d339.json',
  })
  .encode('x', 'height')
  .encode('y', 'weight')
  .encode('color', 'gender')
  .legend('color', {
    position: 'top',
    labelFormatter: key => {
      return "test-legend"
    }
  });

chart.render();

tooltip 的应该通过 mark.tooltip 设置:

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/basement_prod/6b4aa721-b039-49b9-99d8-540b3f87d339.json',
  })
  .encode('x', 'height')
  .encode('y', 'weight')
  .encode('color', 'gender')
  .tooltip({
    title: { valueFormatter: () => 'test-legend' },
  })

chart.render();
posted by pearmini almost 2 years ago

tooltip 的应该通过 mark.tooltip 设置:

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/basement_prod/6b4aa721-b039-49b9-99d8-540b3f87d339.json',
  })
  .encode('x', 'height')
  .encode('y', 'weight')
  .encode('color', 'gender')
  .tooltip({
    title: { valueFormatter: () => 'test-legend' },
  })

chart.render();

谢谢,试了一下,是生效的。 但valueFormatter的回调是否可以给一下必要的数据,比如在这个例子里需要gender的值。


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/basement_prod/6b4aa721-b039-49b9-99d8-540b3f87d339.json',
  })
  .encode('x', 'height')
  .encode('y', 'weight')
  .encode('color', 'gender')
  .tooltip({
    title: {
      valueFormatter: (a, b, c, d) => {
        console.log("value formatter...", a, b, c, d) // 一些必要的信息,但现在是null
        return 'test-legend'
      }
    },
  })

chart.render();
posted by KuduroJS almost 2 years ago

如下的写法就不会是 null 了,需要指定 field 或者 channel:

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/basement_prod/6b4aa721-b039-49b9-99d8-540b3f87d339.json',
  })
  .encode('x', 'height')
  .encode('y', 'weight')
  .encode('color', 'gender')
  .tooltip({
    title: {
      field: 'gender',
      valueFormatter: d => d.toUpperCase()
    },
  })

chart.render();
posted by pearmini almost 2 years ago

谢谢

posted by KuduroJS almost 2 years ago

Fund this Issue

$0.00
Funded

Pull requests