我试图渲染从 firestore 获取的数据并将它们显示到 react-native-chart-kit 中。但是,我总是面临以下错误:
无效编号:M0,0 L-Infinity,181 L64,181
我通过这个函数从数据库中正确获取了数据:
const getweight = () =>
firebase
.firestore()
.collection("weights")
.orderBy("time")
.where("user", "==", "1")
.get()
.then((querySnapshot) => {
let result = [0];
querySnapshot.forEach((doc) => {
result.push(+doc.data().Weight);
});
setDateTracker(date);
if (result.length) {
setWeighTracker(result);
}
});
所以,我得到了包含正确数据的数组。
然后,我将数据推送到以下状态:
const [weightTracker, setWeighTracker] = useState([0]);
当我尝试将数据显示到如下图表时,出现无效数字错误
<LineChart
data={{
datasets: [
{
data: weightTracker.map((item) => {
return item.Weight;
}),
},
],
}}
width={Dimensions.get("window").width} // from react-native
height={220}
yAxisLabel=" KG "
//withVerticalLabels={false}
chartConfig={{
backgroundColor: "#e26a00",
backgroundGradientFrom: "#fb8c00",
backgroundGradientTo: "#ffa726",
decimalPlaces: 0, // optional, defaults to 2dp
color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
style: {
borderRadius: 1,
},
}}
bezier
style={{
marginVertical: 8,
borderRadius: 16,
}}
/>