【问题标题】:Implement Circular progress bar using Recharts使用 Recharts 实现循环进度条
【发布时间】:2018-12-19 05:52:23
【问题描述】:

我正在为 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>

当前看起来像:

想要这样实现:

如何做到这一点?

谢谢

【问题讨论】:

  • 请与我们分享一些代码,以便我们正确理解您的问题并为您提供帮助。
  • @CodeMeNatalie 请查看带有代码的更新问题。

标签: css reactjs charts pie-chart recharts


【解决方案1】:

终于解决了。建议使用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>

【讨论】:

  • 但它会填满整个圈子,不是吗?
【解决方案2】:

从v.1.2.0 属性blendStroke 已添加到PieChart。所以你需要做的就是将它添加到你的 Pie 组件中。希望对你有帮助!

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}
    blendStroke
  >
    <Cell
      key="test"
      fill="#CCC"
    />
  </Pie>
</PieChart>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-30
  • 2013-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多