"use client"; import React, { useState } 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 = ({ data }) => { const [visibleCount, setVisibleCount] = useState(20); // Zeigt zuerst 20 an const [highlighted, setHighlighted] = useState(null); const [chartStartIndex, setChartStartIndex] = useState(0); const appCounts: Record = {}; data.forEach((item) => { appCounts[item.nsapp] = (appCounts[item.nsapp] || 0) + 1; }); const sortedApps = Object.entries(appCounts) .sort(([, a], [, b]) => b - a) .slice(0, visibleCount); 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 (
{sortedApps.map(([name, count]) => ( setHighlighted(name)} onMouseLeave={() => setHighlighted(null)} > ))}
Application Count
{name} {count}
{visibleCount < Object.keys(appCounts).length && ( )}
); }; export default ApplicationChart;