gpt4 book ai didi

javascript - 胜利: Animating Circular Progress Bar - not rendering chart

转载 作者:行者123 更新时间:2023-11-30 21:06:54 25 4
gpt4 key购买 nike

我正在努力将 Victory 的图表库与 React 结合使用来呈现动画循环进度条,如下所示:

https://formidable.com/open-source/victory/gallery/animating-circular-progress-bar

这是我的代码:

import React from 'react';
import {connect} from 'react-redux';
import {VictoryPie, VictoryAnimation, VictoryLabel} from 'victory';




class YourRatings2 extends React.Component {

constructor() {
super();
this.state = {
percent: 25, data: this.getData(0)
};
}

componentDidMount() {
let percent = 25;
}

getData(percent) {
return [{x: 1, y: percent}, {x: 2, y: 100 - percent}];
}

render() {
return (
<section className="YourRatings">
<h2>Core Skills</h2>

<div>
<svg viewBox="0 0 400 400" width="100%" height="100%">
<VictoryPie
animate={{duration: 1000}}
width={400} height={400}
data={this.state.data}
innerRadius={120}
cornerRadius={3}
labels={() => null}
style={{
data: { fill: (d) => {
const color = d.y > 30 ? "green" : "red";
return d.x === 1 ? color : "transparent";
}
}
}}
/>
<VictoryAnimation duration={1000} data={this.state}>
{(newProps) => {
return (
<VictoryLabel
textAnchor="middle" verticalAnchor="middle"
x={200} y={200}
text={`${Math.round(newProps.percent)}%`}
style={{ fontSize: 45 }}
/>
);
}}
</VictoryAnimation>
</svg>
</div>

</section>
);
}
}

const mapStateToProps = state => {
return {
};
};

export default connect(mapStateToProps)(YourRatings2);

不幸的是,这只是渲染文本,而不是完整的图表。见:

enter image description here

关于我做错了什么的任何指示?

最佳答案

我不是这个库的专家,但你给出的例子有一个间隔函数,可以用新的百分比更新 this.state.data。您将初始百分比设置为 0 且未更新。

像示例一样设置间隔或使用下面的示例设置初始状态应该可以解决问题。

示例

constructor() {
super();
this.state = {
percent: 25,
data: this.getData(25)
};
}

关于javascript - 胜利: Animating Circular Progress Bar - not rendering chart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46517397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com