"use client"; import React, { useState } from "react"; import { Pie } from "react-chartjs-2"; import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js"; import ChartDataLabels from "chartjs-plugin-datalabels"; import Modal from "@/components/Modal"; ChartJS.register(ArcElement, Tooltip, Legend, ChartDataLabels); interface ApplicationChartProps { data: { nsapp: string }[]; } const ApplicationChart: React.FC = ({ data }) => { const [isChartOpen, setIsChartOpen] = useState(false); const [isTableOpen, setIsTableOpen] = useState(false); const [chartStartIndex, setChartStartIndex] = useState(0); const [tableLimit, setTableLimit] = useState(20); const appCounts: Record = {}; data.forEach((item) => { appCounts[item.nsapp] = (appCounts[item.nsapp] || 0) + 1; }); const sortedApps = Object.entries(appCounts).sort(([, a], [, b]) => b - a); const chartApps = sortedApps.slice(chartStartIndex, chartStartIndex + 20); const chartData = { labels: chartApps.map(([name]) => name), datasets: [ { label: "Applications", data: chartApps.map(([, count]) => count), backgroundColor: [ "#ff6384", "#36a2eb", "#ffce56", "#4bc0c0", "#9966ff", "#ff9f40", ], }, ], }; return (
setIsChartOpen(false)}>

Top Applications (Chart)

context.chart.data.labels?.[context.dataIndex] || "", }, }, }} />
setIsTableOpen(false)}>

Application Count Table

{sortedApps.slice(0, tableLimit).map(([name, count]) => ( ))}
Application Count
{name} {count}
{tableLimit < sortedApps.length && (
)}
); }; export default ApplicationChart;