使用图表实现循环进度条

时间:2018-12-19 05:52:24

标签: css reactjs charts pie-chart recharts

我将recharts库用于PieCharts。

使用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>

当前外观:

enter image description here

想要这样实现:

enter image description here

如何实现?

谢谢

2 个答案:

答案 0 :(得分:1)

最后得到了解决方案。建议不要使用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>

答案 1 :(得分:0)

来自<ProgressBar numberOfSteps={3} currentStep={1}/>的属性personSchema.pre('save', function (next) { // get the current date var currentDate = new Date(); // change the updated_at field to current date this.updatedAt = currentDate; // if created_at doesn't exist, add to that field if (!this.createdAt) { this.createdAt = currentDate; } next(); }); const newPerson = new Person(); let name ='x' let family = 'y' . . . Object.assign(newPerson, req.body, { name: name, }); newPerson.save((err, log) => { if (err) return next(err) }); 已添加到v.1.2.0。因此,您需要做的是将其添加到Pie组件中。希望对您有帮助!

blendStroke