ant-design / ant-design-charts

A React Chart Library
https://ant-design-charts.antgroup.com/
MIT License
1.95k stars 364 forks source link

🧐How can I make pie chart to display contrast colors for the labels? #767

Closed simplycodepix closed 3 years ago

simplycodepix commented 3 years ago

My config:

const options = {
    data: chartData,
    angleField: 'value',
    colorField: 'label',
    color: customColors || colors,
    radius: 1,
    innerRadius: 0.6,
    position: 'left',
    label: {
      type: 'inner',
      offset: '-50%',
      style: {
        textAlign: 'center',
        fontSize: 14,
      },
    },
    appendPadding: 0,
    padding: [0, 0, 0, -150],
    interactions: [{ type: 'element-selected' }, { type: 'element-active' }],
    statistic: {
      title: false,
    },
  };

The chart looks like this, right now: image

I want the "billable" label to show the value in black color. How can I do that?

visiky commented 3 years ago

see: https://g2plot.antv.vision/en/examples/component/legend#legend-item-cfg

simplycodepix commented 3 years ago

Thanks, it's cool. But the question is about labels, not legends. For legends, there is some documentation that describes how we can customize those things. But for labels, it seems like we can't change values dynamically, please, see - https://g2plot.antv.vision/en/docs/api/components/label/#gatsby-focus-wrapper

I want this value to be in black image

simplycodepix commented 3 years ago

The config with solution looks like this:

const config = {
    label: {
      layout: [
        { type: 'adjust-color' },
      ],
    },
};

image