css - 使用 Recharts 实现循环进度条

标签 css reactjs charts pie-chart recharts

我正在使用 recharts饼图库。

使用 paddingAngle={0} 可以移除填充 Angular 但想要移除单元格分隔符(白色)。

代码:

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>

当前看起来像:

enter image description here

想这样实现:

enter image description here

如何实现?

谢谢

最佳答案

终于找到解决办法了。建议使用 RadialBarChart

,而不是使用 PieChart 进行变通

解决方法:

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>

关于css - 使用 Recharts 实现循环进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53845317/

相关文章:

html - 当表格容器具有 Overflow-x auto 时,工具提示会被切断

javascript - 如何将 json 对象插入 Google 图表线

charts - 与谷歌应用程序发明者一起绘制图表

wpf 图表图例

css - SVG 作为背景图像未出现

html - 使 iframe 成为其容器的 100% 宽度

javascript - 使用 Antd 表列和列组的替代方法

css - 弹出窗口内的输入字段在聚焦时跳跃

css - 为什么我的 Div 不以其父级为中心?

javascript - 语义UI React下拉搜索allowAddition,如何区分onchange事件中的添加?