如何在 react-native-chart-kit 中显示 mongodb 数据?

问题描述

我正在尝试使用 react native 的 chart-kit 包在我的 react native 图表中显示值。我在图集中有这种结构和 4 条记录:

_id: <RANDOM NUMBER>
name:"Armanino"
request:"Dhanjay"
subject:"VPN"
category:"IT"
priority:"Medium"
desc:"Installation"
location:"Pune"
status:"In Process"
date:"2/23/2021"

_id: <RANDOM NUMBER>
name:"Armanino"
request:"Dhanjay"
subject:"VPN"
category:"IT"
priority:"Medium"
desc:"Installation"
location:"Pune"
status:"Closed"
date:"2/23/2021"


_id: <RANDOM NUMBER>
name:"Armanino"
request:"John"
subject:"Firewall"
category:"DBA"
priority:"High"
desc:"Virus"
location:"Shimla"
status:"Resolved"
date:"2/23/2021"


_id: <RANDOM NUMBER>
name:"Armanino"
request:"Dhanjay"
subject:"display"
category:"IT"
priority:"Medium"
desc:"Settings"
location:"Delhi"
status:"Open"
date:"2/23/2021"

到目前为止,我已经尝试过这个,但得到像 underfined is not an object (evaluating: 'data.map')错误

const [chartData,setChartData] = useState({});
useEffect(() => {
        chart();
    },[]);
const chart = () => {
        let status = [];
        let dates = [];

        axios.get("https://cowardly-chipmunk-13.loca.lt/")
            .then(res => {
                for (const stats of res.data) {
                   dates.push(stats.date)
                   status.push(stats.status)
                }
                
                setChartData({
                    labels: dates,data: status
                })
            })
            .catch(err => {
                console.log(err);
            });
    }
return (
<BarChart
                    style={{ borderRadius: 16 }}
                    data={chartData}
                    width={screenWidth}
                    height={400}
                    chartConfig={chartConfig}
                    verticalLabelRotation={30}
                />
);

到目前为止,我所理解的可能是我没有整数值,因此我尝试使用 nodejs 的 countDocuments 仍然没有用?有什么建议或帮助吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...