亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

更新由: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 關注
  • 123 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號