antvis/G2

饼图 label的连接线以及标题颜色 没有自动跟 color通道颜色对应 #6514

Knight-ZXW posted onGitHub

问题描述

饼图 label的连接线以及标题颜色 没有自动跟 color通道颜色对应

重现链接

No response

重现步骤

示例代码.来自官方文档 https://g2.antv.antgroup.com/zh/examples/general/pie/#spider-label-overlap

/**
 * A recreation of this demo: https://nivo.rocks/pie/
 */
import { Chart } from '@antv/g2';

const chart = new Chart({
  container: 'container',
});

chart;

chart
  .interval()
  .data([
    { type: '微博', value: 93.33 },
    { type: '其他', value: 6.67 },
    { type: '论坛', value: 4.77 },
    { type: '网站', value: 1.44 },
    { type: '微信', value: 1.12 },
    { type: '客户端', value: 1.05 },
    { type: '新闻', value: 0.81 },
    { type: '视频', value: 0.39 },
    { type: '博客', value: 0.37 },
    { type: '报刊', value: 0.17 },
  ])
  .encode('y', 'value')
  .encode('color', 'type')
  .transform({ type: 'stackY' })
  .coordinate({ type: 'theta' })
  .animate('enter', { type: 'waveIn' })
  .label({
    position: 'spider',
    text: (d) => `${d.type} (${d.value})`,
  })
  .legend(false);

chart.render();

预期行为

label 的连接线 以及文字应该有颜色,这样更好区分数据

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]

屏幕截图或视频(可选)

image

补充说明(可选)

No response


颜色需要和饼图扇形的颜色保持一致吗?

.label({
    position: 'spider',
    text: (d) => `${d.type} (${d.value})`,
    fill: 'red',
    connectorStroke: 'red',
  })

以上可以指定 文本和连接线的颜色。如果要和扇形颜色保持一致,需要扇形的 color 和这里两个配置都是用回调函数的形式,并未回调函数采用同一个逻辑。

这个回调函数就是根据图形的值,返回特定的颜色。

posted by hustcc 6 months ago

Fund this Issue

$0.00
Funded

Pull requests