-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.js
More file actions
101 lines (89 loc) · 3.14 KB
/
Copy pathtest2.js
File metadata and controls
101 lines (89 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React, { useState, useEffect } from 'react'
import { View, Text, Image, TouchableHighlight, Flatlist, TouchableOpacity } from 'react-native'
import styles from './styles/components/cartItem.style'
import {db} from './firebase';
import { collection, getDocs, orderBy, query, where } from 'firebase/firestore';
import {
LineChart,
BarChart,
PieChart,
ProgressChart,
ContributionGraph,
StackedBarChart
} from "react-native-chart-kit";
import { Dimensions } from "react-native";
const screenWidth = Dimensions.get("window").width;
export default function Chart() {
const [total, setTotal] = useState([])
const [mont, setMont] = useState([])
const fetchMonth = collection(db, "test");
const totally = query(fetchMonth, where("year", "==", "2022"), where("user", "==", "a1"))
const uniqueMonth = []
var totalHarga = 0;
useEffect(()=>{
const fetching = async () => {
const findMonth = await getDocs(totally)
const bulan = []
findMonth.forEach((doc)=>{
console.log(doc.id)
bulan.push(doc.data().month)
const funcBaru = async () => {
const fetchTotal = collection(db, "test", doc.id, "testinside")
const getMonth = await getDocs(fetchTotal)
const harga = []
getMonth.forEach((price) => {
console.log(price.data().total)
totalHarga = totalHarga + price.data().total
console.log(totalHarga + "totalHarga")
harga.push(totalHarga)
})
console.log(harga)
setTotal(harga)
}
funcBaru()
})
bulan.forEach((c) => {
if(!uniqueMonth.includes(c)){
uniqueMonth.push(c)
}
})
//console.log(uniqueMonth)
setMont(uniqueMonth)
}
fetching()
},[])
const data = {
labels: mont,
datasets: [
{
data: total,
// data: mont,
color: (opacity = 1) => `rgba(134, 65, 244, ${opacity})`, // optional
strokeWidth: 2 // optional
}
],
legend: ["Rainy Days"] // optional
};
const chartConfig = {
backgroundColor: "#e26a00",
backgroundGradientFrom: "#fb8c00",
backgroundGradientTo: "#ffa726",
decimalPlaces: 2, // optional, defaults to 2dp
color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
labelColor: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
};
return(
<View style={{marginTop:100, marginLeft:50, marginRight:50}}>
{/* <TouchableOpacity onPress={fetching}>
<Text>fetch</Text>
</TouchableOpacity> */}
<LineChart
data={data}
width={320}
height={220}
chartConfig={chartConfig}
bezier
/>
</View>
)
}