为了账号安全,请及时绑定邮箱和手机立即绑定

更新由:RNSVGPath InvalidNumber 管理的视图的属性“d”时如何解决错误

更新由:RNSVGPath InvalidNumber 管理的视图的属性“d”时如何解决错误

PHP
森栏 2022-10-14 14:55:11
我需要使用 react-native-chart-kit 加载我的 SQL 服务器数据,但是当我使用此代码时,我收到此错误:更新由以下人员管理的视图的属性“d”时出错:RNSVGPath null InvalidNumberimport React from "react";import { Text, View, Dimensions } from "react-native";import { LineChart } from "react-native-chart-kit";export default class Home extends React.Component {  constructor(props) {    super(props);    this.state = {      isLoading: true,      data: {        labels: [          "Gen",          "Feb",          "Mar",          "Apr",          "Mag",          "Giu",          "Lug",          "Ago",          "Set",          "Ott",          "Nov",          "Dic",        ],        datasets: [          {            data: [],          },        ],      },    };  }  GetData = () => {    const self = this;    return fetch("http://192.168.1.5:80/graph.php")      .then((response) => response.json())      .then((responseJson) => {        // clone the data from the state        const dataClone = { ...self.state.data };        const values = responseJson.map((value) => value.ChiffreAffaire);        dataClone.datasets[0].data = values;        self.setState({          isLoading: false,          data: dataClone,        });      })      .catch((error) => {        console.error(error);      });  };  render() {    return (      <View>        <LineChart          data={this.state.data}          width={Dimensions.get("window").width} // from react-native          height={220}          yAxisLabel={"$"}          chartConfig={chartConfig}          bezier          style={{            marginVertical: 8,            borderRadius: 16,          }}        />      </View>    );  }}我从我的 php 文件中获得的数据如下:[{"ChiffreAffaire":"4800.00"},{"ChiffreAffaire":"12000.00"}]我不知道问题是什么以及为什么会出现此错误;请如果你有任何想法
查看完整描述

2 回答

?
梦里花落0921

TA贡献1772条经验 获得超6个赞

我解决了我的问题!!!!对于那些有同样问题的人,我会向你解释错误:问题是我的 LineChart 在完全重新加载之前获取数据,因此它变为空,这是一个无效的数字格式;


所以你要做的是在返回之前添加渲染方法:


 if(this.state.isLoading){

    return(

      <View style={{flex: 1, padding: 20}}>

          <ActivityIndicator/>

        </View>


    )

  }

因此,在加载所有数据之前,我们不会传递给 LineChart


查看完整回答
反对 回复 2022-10-14
?
阿波罗的战车

TA贡献1862条经验 获得超6个赞

这对我有用:


{

    this.state.loadComplete &&

        (<LineChart

            data={this.state.dt}

            width={Dimensions.get("window").width} // from react-native

            height={this.height}

            yAxisLabel=""

            yAxisSuffix="b"

            yAxisInterval={1} // optional, defaults to 1

            chartConfig={this.config}

            bezier

            style={{

                marginVertical: 8,

                borderRadius: 16

            }}

        />)

}


查看完整回答
反对 回复 2022-10-14
  • 2 回答
  • 0 关注
  • 98 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号