首页 > 解决方案 > 使用 Recharts 实现循环进度条

问题描述

我正在为 PieCharts 使用recharts库。

能够移除填充角但想要移除单元分隔符(paddingAngle={0}白色)。

代码:

const data = [
            { id: "1", name: "L1", value: 75 },
            { id: "2", name: "L2", value: 25 }
            ];

<PieChart width={50} height={50}>
  <text
    x={25}
    y={25}
    textAnchor="middle"
    dominantBaseline="middle"
  >
    25
  </text>
  <Pie
    data={data}
    dataKey="value"
    innerRadius="80%"
    outerRadius="100%"
    fill="#82ca9d"
    startAngle={90}
    endAngle={-270}
    paddingAngle={0}
    cornerRadius={5}
  >
    <Cell
      key="test"
      fill="#CCC"
    />
  </Pie>
</PieChart>

当前看起来像:

在此处输入图像描述

想这样实现:

在此处输入图像描述

如何做到这一点?

谢谢

标签: cssreactjschartspie-chartrecharts

解决方案


终于得到了解决方案。建议不要使用 解决方法,而是PieChart建议使用RadialBarChart

解决方案:

const data = [
  { name: 'L1', value: 25 }
];

const circleSize = 30;

<RadialBarChart
  width={circleSize}
  height={circleSize}
  cx={circleSize / 2}
  cy={circleSize / 2}
  innerRadius={12}
  outerRadius={18}
  barSize={2}
  data={data}
  startAngle={90}
  endAngle={-270}
  >
  <PolarAngleAxis
  type="number"
  domain={[0, 100]}
  angleAxisId={0}
  tick={false}
  />
  <RadialBar
  background
  clockWise
  dataKey="value"
  cornerRadius={circleSize / 2}
  fill="#82ca9d"
  />
  <text
  x={circleSize / 2}
  y={circleSize / 2}
  textAnchor="middle"
  dominantBaseline="middle"
  className="progress-label"
  >
  25
  </text>
</RadialBarChart>

推荐阅读