mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-19 22:14:07 +01:00
Completed DonutChart.
This commit is contained in:
parent
94dcee07d8
commit
1f665981ae
@ -2,11 +2,7 @@ import { BarChart, Card, Title } from "@tremor/react";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import axiosInstance from "../../api/configs/AxiosConfig";
|
import axiosInstance from "../../api/configs/AxiosConfig";
|
||||||
|
|
||||||
const apiGetBarChartData = () => {
|
|
||||||
return axiosInstance.get("dashboard/stats/");
|
|
||||||
}
|
|
||||||
console.log(apiGetBarChartData);
|
|
||||||
|
|
||||||
const chartdata3 = [
|
const chartdata3 = [
|
||||||
{
|
{
|
||||||
date: "Jan 23",
|
date: "Jan 23",
|
||||||
|
|||||||
39
frontend/src/components/dashboard/DonutChart.jsx
Normal file
39
frontend/src/components/dashboard/DonutChart.jsx
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { DonutChart } from "@tremor/react";
|
||||||
|
import axiosInstance from "../../api/configs/AxiosConfig";
|
||||||
|
|
||||||
|
const fetchDonutData = async () => {
|
||||||
|
try {
|
||||||
|
let res = await axiosInstance.get("/dashboard/stats/");
|
||||||
|
let todoCount = res.data.todo_count;
|
||||||
|
let recurrenceCount = res.data.recurrence_count;
|
||||||
|
if (todoCount === undefined) {
|
||||||
|
todoCount = 0;
|
||||||
|
}
|
||||||
|
if (recurrenceCount === undefined) {
|
||||||
|
recurrenceCount = 0;
|
||||||
|
}
|
||||||
|
const donutData = [
|
||||||
|
{ name: "Todo", count: todoCount },
|
||||||
|
{ name: "Recurrence", count: recurrenceCount },
|
||||||
|
];
|
||||||
|
return donutData;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching donut data:", error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const donutDataArray = await fetchDonutData();
|
||||||
|
export default function DonutChartGraph() {
|
||||||
|
return (
|
||||||
|
<DonutChart
|
||||||
|
className="mt-6"
|
||||||
|
data={donutDataArray}
|
||||||
|
category="count"
|
||||||
|
index="name"
|
||||||
|
colors={["rose", "yellow", "orange"]}
|
||||||
|
onValueChange={(v) => setValue(v)}
|
||||||
|
showAnimation
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -1,20 +1,23 @@
|
|||||||
import { Card, Grid, Tab, TabGroup, TabList, TabPanel, TabPanels, Text, Title, DonutChart } from "@tremor/react";
|
import {
|
||||||
|
Card,
|
||||||
|
Grid,
|
||||||
|
Tab,
|
||||||
|
TabGroup,
|
||||||
|
TabList,
|
||||||
|
TabPanel,
|
||||||
|
TabPanels,
|
||||||
|
Text,
|
||||||
|
Title,
|
||||||
|
DonutChart,
|
||||||
|
Legend,
|
||||||
|
} from "@tremor/react";
|
||||||
import KpiCard from "./kpiCard";
|
import KpiCard from "./kpiCard";
|
||||||
import { BarChartGraph } from "./Barchart";
|
import { BarChartGraph } from "./Barchart";
|
||||||
|
import DonutChartGraph from "./DonutChart";
|
||||||
|
|
||||||
const cities = [
|
|
||||||
{
|
|
||||||
name: "New York",
|
|
||||||
sales: 9800,
|
|
||||||
},
|
|
||||||
// ...
|
|
||||||
{
|
|
||||||
name: "Zurich",
|
|
||||||
sales: 1398,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const valueFormatter = number => `$ ${new Intl.NumberFormat("us").format(number).toString()}`;
|
const valueFormatter = (number) =>
|
||||||
|
`$ ${new Intl.NumberFormat("us").format(number).toString()}`;
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function Dashboard() {
|
||||||
return (
|
return (
|
||||||
@ -41,16 +44,15 @@ export default function Dashboard() {
|
|||||||
{/* Placeholder to set height */}
|
{/* Placeholder to set height */}
|
||||||
<div className="h-31">
|
<div className="h-31">
|
||||||
<Card className="mx-auto h-full">
|
<Card className="mx-auto h-full">
|
||||||
<Title>Sales</Title>
|
<Title>Tasks</Title>
|
||||||
<DonutChart
|
<DonutChartGraph />
|
||||||
className="mt-6"
|
<br/>
|
||||||
data={cities}
|
<Legend
|
||||||
category="sales"
|
className="mt-3 mx-auto w-1/2"
|
||||||
index="name"
|
categories={["Todo Task", "Recurrence Task"]}
|
||||||
colors={["rose", "yellow", "orange", "indigo", "blue", "emerald"]}
|
colors={["rose", "yellow"]}
|
||||||
onValueChange={v => setValue(v)}
|
|
||||||
showAnimation
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
<BarChartGraph />
|
<BarChartGraph />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user