mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-02-01 17:31:49 +00:00
Create ApplicationChart.tsx
This commit is contained in:
parent
d3882b6818
commit
7299b77359
47
frontend/src/components/ApplicationChart.tsx
Normal file
47
frontend/src/components/ApplicationChart.tsx
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { Pie } from "react-chartjs-2";
|
||||||
|
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js";
|
||||||
|
|
||||||
|
ChartJS.register(ArcElement, Tooltip, Legend);
|
||||||
|
|
||||||
|
interface ApplicationChartProps {
|
||||||
|
data: { nsapp: string }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const ApplicationChart: React.FC<ApplicationChartProps> = ({ data }) => {
|
||||||
|
const chartData = () => {
|
||||||
|
const appCounts: Record<string, number> = {};
|
||||||
|
|
||||||
|
data.forEach((item) => {
|
||||||
|
appCounts[item.nsapp] = (appCounts[item.nsapp] || 0) + 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
labels: Object.keys(appCounts),
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: "Applications",
|
||||||
|
data: Object.values(appCounts),
|
||||||
|
backgroundColor: [
|
||||||
|
"#ff6384",
|
||||||
|
"#36a2eb",
|
||||||
|
"#ffce56",
|
||||||
|
"#4bc0c0",
|
||||||
|
"#9966ff",
|
||||||
|
"#ff9f40",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-1/2 mx-auto my-6">
|
||||||
|
<Pie data={chartData()} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ApplicationChart;
|
Loading…
x
Reference in New Issue
Block a user