2023-10-24 08:32:31 +00:00
|
|
|
import { useWindowDimensions } from "react-native";
|
|
|
|
import { PieChart } from "react-native-chart-kit";
|
2023-10-26 05:53:01 +00:00
|
|
|
import { useTheme } from "react-native-paper";
|
2023-10-24 08:32:31 +00:00
|
|
|
|
|
|
|
export interface Option {
|
|
|
|
value: number;
|
|
|
|
label: string;
|
|
|
|
}
|
|
|
|
|
2023-10-28 02:10:58 +00:00
|
|
|
export default function AppPieChart({ options }: { options: Option[] }) {
|
2023-10-24 08:32:31 +00:00
|
|
|
const { width } = useWindowDimensions();
|
2023-10-26 05:53:01 +00:00
|
|
|
const { colors } = useTheme();
|
2023-10-24 08:32:31 +00:00
|
|
|
|
|
|
|
const pieChartColors = [
|
|
|
|
"#1f77b4", // Blue
|
|
|
|
"#ff7f0e", // Orange
|
|
|
|
"#2ca02c", // Green
|
|
|
|
"#d62728", // Red
|
|
|
|
"#9467bd", // Purple
|
|
|
|
"#8c564b", // Brown
|
|
|
|
"#e377c2", // Pink
|
|
|
|
"#7f7f7f", // Gray
|
|
|
|
];
|
|
|
|
|
|
|
|
const data = options.map((option, index) => ({
|
|
|
|
name: option.label,
|
|
|
|
value: option.value,
|
|
|
|
color: pieChartColors[index],
|
2023-10-26 05:53:01 +00:00
|
|
|
legendFontColor: colors.onSurface,
|
2023-10-24 08:32:31 +00:00
|
|
|
legendFontSize: 15,
|
|
|
|
}));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<PieChart
|
|
|
|
data={data}
|
|
|
|
paddingLeft="0"
|
|
|
|
width={width}
|
|
|
|
height={220}
|
|
|
|
chartConfig={{
|
|
|
|
backgroundColor: "#e26a00",
|
|
|
|
backgroundGradientFrom: "#fb8c00",
|
|
|
|
backgroundGradientTo: "#ffa726",
|
|
|
|
color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
|
|
|
|
labelColor: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
|
|
|
|
style: {
|
|
|
|
borderRadius: 16,
|
|
|
|
},
|
|
|
|
propsForDots: {
|
|
|
|
r: "6",
|
|
|
|
strokeWidth: "2",
|
|
|
|
stroke: "#ffa726",
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
accessor={"value"}
|
|
|
|
backgroundColor={"transparent"}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|