graph works
This commit is contained in:
parent
84dbae49c1
commit
4b06a217c5
2 changed files with 16 additions and 43 deletions
|
|
@ -1,33 +1,13 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { ScrollView, StyleSheet, View } from 'react-native';
|
import { SafeAreaView } from 'react-native';
|
||||||
import { Graph } from '../../../components';
|
import { Graph } from '../../../components';
|
||||||
import { useTheme } from '../../contexts/ThemeContext';
|
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const { colors } = useTheme();
|
|
||||||
|
|
||||||
// Mock data #TODO Database einbinden
|
|
||||||
// what to do when amount too small?
|
|
||||||
|
|
||||||
const spent = 120.75;
|
|
||||||
const budget = 696.96;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
flex: 1,
|
|
||||||
backgroundColor: colors.backgroundColor,
|
|
||||||
marginTop: 50,
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<SafeAreaView style={{flex: 1}}>
|
||||||
<ScrollView>
|
|
||||||
|
|
||||||
<Graph/>
|
<Graph/>
|
||||||
|
|
||||||
|
|
||||||
{/* <DebugMenu />
|
{/* <DebugMenu />
|
||||||
|
|
@ -45,7 +25,6 @@ export default function Page() {
|
||||||
<Widget>
|
<Widget>
|
||||||
<SavingsOverview/>
|
<SavingsOverview/>
|
||||||
</Widget> */}
|
</Widget> */}
|
||||||
</ScrollView>
|
</SafeAreaView>
|
||||||
</View>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,29 @@
|
||||||
import { useEffect } from "react";
|
import { Dimensions, View } from "react-native";
|
||||||
import { PieChart } from "react-native-chart-kit";
|
import { PieChart } from "react-native-chart-kit";
|
||||||
|
import { useTheme } from "../../app/contexts/ThemeContext";
|
||||||
import useFetch from "../../hooks/useFetch";
|
import useFetch from "../../hooks/useFetch";
|
||||||
|
|
||||||
const Graph = () => {
|
const Graph = () => {
|
||||||
|
const {colors} = useTheme();
|
||||||
|
|
||||||
const {data, isLoading, reFetch} = useFetch({sql: "SELECT c.name AS name, c.color AS color, SUM(e.amount) as total FROM category c LEFT JOIN expense e ON e.category_guid = c.guid GROUP BY c.guid", args: []});
|
const {data} = useFetch({sql: "SELECT c.name AS name, c.color AS color, SUM(e.amount) as total FROM category c LEFT JOIN expense e ON e.category_guid = c.guid GROUP BY c.guid", args: []});
|
||||||
|
const acctual_data = data.map(item => ({...item, legendFontColor: colors.primaryText, legendFontSize: 14}));
|
||||||
useEffect(() => {
|
|
||||||
console.log(data);
|
|
||||||
}, [data])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<View style={{backgroundColor: colors.backgroundColor, borderRadius: 10, margin: 10}}>
|
||||||
<PieChart
|
<PieChart
|
||||||
data={data}
|
data={acctual_data}
|
||||||
width={333}
|
width={Dimensions.get("window").width}
|
||||||
height={333}
|
height={240}
|
||||||
chartConfig={{
|
chartConfig={{
|
||||||
backgroundColor: '#e26a00',
|
|
||||||
backgroundGradientFrom: '#fb8c00',
|
|
||||||
backgroundGradientTo: '#ffa726',
|
|
||||||
decimalPlaces: 2, // optional, defaults to 2dp
|
|
||||||
color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
|
color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
|
||||||
style: {
|
|
||||||
borderRadius: 16
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
|
backgroundColor="transparent"
|
||||||
accessor="total"
|
accessor="total"
|
||||||
backgroundColor="red"
|
|
||||||
paddingLeft="15"
|
paddingLeft="15"
|
||||||
absolute
|
avoidFalseZero={true}
|
||||||
/>
|
/>
|
||||||
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue