javascript - Animate endAngle of Victory Pie Chart in React Native componentDidMount
问题描述
I'm using Victory Native charts in React Native and am attempting to animate the endAngle of Victory Pie chart from 0 to 360 to produce an effect similar to this.
I include a simplified version of my code. Simplified in the sense that I have hardcoded the dynamic data into the initial state. My code is as follows:
import React, {Component} from "react";
import {Animated, View} from "react-native";
import {VictoryPie} from "victory-native";
export default class PieGraph extends Component {
state = {
data: [
{
"color": "#D8BDC4",
"y": 6,
},
{
"color": "#D88196",
"y": 1,
},
{
"color": "#B73756",
"y": 3,
},
],
total: 10,
endAngle: new Animated.Value(0),
};
componentDidMount() {
Animated.timing(this.state.endAngle, {toValue: 360, duration: 2000}).start();
}
render() {
const {data, total, endAngle} = this.state;
return (
<View style={{paddingTop: 40}}>
<VictoryPie
animate={{duration: 2000}}
data={data}
labels={datum => total ? `${Math.round((datum.y / total) * 100)}%` : ''}
colorScale={data.map(({color}) => color)}
startAngle={0}
endAngle={endAngle}
/>
</View>
)
}
}
When animating the endAngle as above, the chart doesn't appear despite this.state.endAngle changing from 0 to 360. No errors or warnings were output.
When defining a static value for the endAngle prop less than 360 but above 0, the chart instantly appears in that state. When omitting the endAngle prop it instantly appears as a full circle.
I have also tried starting animation as a callback on the onLoad.before
property on the animate prop, but still get the same result.
解决方案
推荐阅读
- facebook - 我可以使用 graph-api 获取任何页面的 page-fans-country 吗?
- android - 加载音频文件时显示进度条
- json - 社交博客应用程序中喜欢/收藏的数据结构
- c++11 - 如果我想转移一个资源,我应该选择哪种参数类型?弱点?或 shared_ptr
- php - 用于在一系列文件中进行 grep 的 Shell 脚本
- angularjs - Angularjs 材料的 md 复选框无法正常工作
- apache-spark - 如何从 REST API 创建 Spark 长时间运行的上下文?
- c# - 当从 color='blue' 的表中选择 id 时如何在 asp.net(c#) 上显示表
- python - 对产品类执行 CRUD 操作?
- html - “object-fit:cover”不起作用