'use client' import { useState } from 'react' type ChartDataPoint = { name: string value: number } export function RevenueChart({ data }: { data: ChartDataPoint[] }) { const [hoveredIdx, setHoveredIdx] = useState(null) if (!data || data.length === 0) { return (
Keine Umsatzdaten vorhanden.
) } const width = 500 const height = 200 const paddingLeft = 55 const paddingRight = 15 const paddingTop = 25 const paddingBottom = 30 const chartWidth = width - paddingLeft - paddingRight const chartHeight = height - paddingTop - paddingBottom const maxVal = Math.max(...data.map(d => d.value), 100) const maxValue = Math.ceil(maxVal * 1.15) // 15% headroom const points = data.map((d, i) => { const x = paddingLeft + (i / (data.length - 1)) * chartWidth const y = paddingTop + chartHeight - (d.value / maxValue) * chartHeight return { x, y, name: d.name, value: d.value } }) const linePath = points.map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x} ${p.y}`).join(' ') const areaPath = points.length > 0 ? `${linePath} L ${points[points.length - 1].x} ${paddingTop + chartHeight} L ${points[0].x} ${paddingTop + chartHeight} Z` : '' // 4 ticks for grid const yTicks = [0, 0.33, 0.66, 1].map(ratio => Math.round(maxValue * ratio)) return (
{/* Grid Lines */} {yTicks.map((val, idx) => { const y = paddingTop + chartHeight - (val / maxValue) * chartHeight return ( {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR', maximumFractionDigits: 0 }).format(val)} ) })} {/* X Axis Labels */} {points.map((p, i) => ( {p.name} ))} {/* Area under the line */} {areaPath && ( )} {/* Line */} {linePath && ( )} {/* Interactive Dots & Hover areas */} {points.map((p, i) => ( {/* Thick hover circle area */} setHoveredIdx(i)} onMouseLeave={() => setHoveredIdx(null)} /> {/* Visual Point dot */} {hoveredIdx === i && ( )} ))} {/* HTML Tooltip overlay */} {hoveredIdx !== null && (

{points[hoveredIdx].name}

{new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(points[hoveredIdx].value)}

)}
) }