动态数据不显示在 React Native 中?

Dynamic data not displaying in react native?

我尝试使用以下逻辑在我的 React Native 中显示动态数据。但它只显示一次数据,如果我刷新我的应用程序,它会一次又一次地给出错误: 错误就像 undefined is not an object('data.map') 有点....如果逻辑错误,我的逻辑中遗漏了什么,谁能帮助我?

问题是有时候数据显示一次都显示不出来

const [chartData, setChartData] = useState({});

    const chart = () => {
        let status = [];
        let dates = [];
        let count = 0;
        let count1 = 0;
        let count2 = 0;
        let count3 = 0;
        let count4 = 0;

        fetch("<API CALL>")
        .then(res => res.json())
        .then(results => {
            for (const stats of results) {
                if (stats.status == "Open") {
                    count = count + 1;
                }
                else if (stats.status == "Closed") {
                    count1 = count1 + 1;
                }
                else if (stats.status == "Resolved") {
                    count2 = count2 + 1;
                }
                else if (stats.status == "In Process") {
                    count3 = count3 + 1;
                }
            }
            count4 = count3 + count2 + count1 + count;
            setChartData({
                    labels: ["Open", "Closed", "Resolved", "In Process"],
                    datasets: [
                        {
                            data: [count, count1, count2, count3]
                        }
                    ]
            })
        })
        console.log(chartData);
    }

    useEffect(() => {
        chart();
    }, []);
<BarChart
                    style={{ borderRadius: 16 }}
                    data={chartData}
                    width={screenWidth}
                    height={400}
                    chartConfig={chartConfig}
                    verticalLabelRotation={30}
                />

存储在monogdb atlas中的数据

_id:<RANDOM_ID>
name:"Jade Labs access"
request:"Dhanjay"
subject:"PI RPA"
category:"IT"
priority:"High"
desc:"RPA project"
location:"Pune"
status:"Resolved"
date:"2/23/2021"
__v:0
assign:"Dhanjay Bhardwaj"

尝试一下是否有效

   {chartData.datasets != undefined ? (<BarChart
                        style={{ borderRadius: 16 }}
                        data={chartData}
                        width={screenWidth}
                        height={400}
                        chartConfig={chartConfig}
                        verticalLabelRotation={30}
                    />):null}

它应该在有数据时加载 barchat