我想通过 API 调用获取数值并使用“react-native-chart-kit”在图形中表示它们,但它产生的错误 data[0].toFixed 不是一个函数。如何解决此错误?点击这里查看错误
class SecondActivity extends Component {
constructor(props){
super(props);
this.state={a:"",b:""}
}
componentDidMount(){
this.graph = setInterval( () => this.GetGraph(),1000);
}
GetGraph(){
var jsondata;
fetch('api here', {
method: 'GET'
})
.then((response) => response.json())
.then((responseJson) => {
this.setState({
jsondata: responseJson,
a:responseJson[0].val,
b:responseJson[1].val,})
})
.catch((error) => {
console.error(error);
}); }
render() {
if(!this.state.a) {
return <ActivityIndicator/>
}
return (
<View>
<LineChart
data={{
labels: [
'1',
'2', ],
datasets: [
{
data: [
this.state.a,
this.state.b,
],
}, ], }}
width={Dimensions.get('window').width}
height={250}
yAxisLabel="a"
yAxisInterval={1}/>
</View>);}}