83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
import apiFetch from "@/lib/apiFetch";
|
|
import { Card, Divider, Flex, Stack, Title } from "@mantine/core";
|
|
import { IconSettings } from "@tabler/icons-react";
|
|
import type { EChartsOption } from "echarts";
|
|
import EChartsReact from "echarts-for-react";
|
|
import { useEffect, useState } from "react";
|
|
import useSWR from "swr";
|
|
|
|
export default function DashboardGrafik() {
|
|
const [options, setOptions] = useState<EChartsOption>({});
|
|
const { data, mutate, isLoading } = useSWR(
|
|
"grafik-dashboard",
|
|
async () => {
|
|
return apiFetch.api.dashboard.grafik.get().then(res => res.data);
|
|
}
|
|
);
|
|
|
|
const loadData = () => {
|
|
if (!data) return;
|
|
const option: EChartsOption = {
|
|
darkMode: true,
|
|
animation: true,
|
|
legend: {
|
|
textStyle: { color: "#fff" } // warna legend putih
|
|
},
|
|
tooltip: {},
|
|
dataset: {
|
|
dimensions: data.dimensions,
|
|
source: data.source
|
|
},
|
|
xAxis: {
|
|
type: "category",
|
|
axisLabel: { color: "#fff" }
|
|
},
|
|
yAxis: {
|
|
type: "value",
|
|
minInterval: 1
|
|
},
|
|
color: ["#1abc9c", "#10816aff"],
|
|
series: [
|
|
{ type: "bar" },
|
|
{ type: "bar" }
|
|
]
|
|
};
|
|
|
|
setOptions(option);
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (data) loadData();
|
|
}, [data]);
|
|
|
|
return (
|
|
<Card
|
|
radius="lg"
|
|
p="xl"
|
|
withBorder
|
|
style={{
|
|
background:
|
|
"linear-gradient(145deg, rgba(25,25,25,0.95), rgba(45,45,45,0.85))",
|
|
borderColor: "rgba(100,100,100,0.2)",
|
|
boxShadow: "0 0 25px rgba(0,255,200,0.08)",
|
|
}}
|
|
>
|
|
<Stack gap="md">
|
|
<Flex align="center" justify="space-between">
|
|
<Title order={4} c="gray.0">
|
|
System Performance
|
|
</Title>
|
|
<IconSettings size={20} color="gray" />
|
|
</Flex>
|
|
<Divider my="xs" />
|
|
<Stack gap="sm">
|
|
<EChartsReact style={{ height: 400, width: "100%" }} option={options} />
|
|
{/* <ProgressSection label="CPU Usage" value={68} color="teal" />
|
|
<ProgressSection label="Memory Usage" value={75} color="cyan" />
|
|
<ProgressSection label="Network Load" value={42} color="blue" />
|
|
<ProgressSection label="Disk Space" value={88} color="red" /> */}
|
|
</Stack>
|
|
</Stack>
|
|
</Card>
|
|
)
|
|
} |