Match ShadCN interactive bar chart style

- Remove cursor={false} to enable hover highlight
- Remove rounded bar corners for flat ShadCN look
- Remove explicit stroke/color on grid and axes (inherit from CSS)
- Use var(--color-{metric}) for bar fill
- Reduce chart height to 250px (ShadCN default)
- Simplify bar props to match ShadCN minimal pattern

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Usman Baig
2026-03-09 13:37:00 +01:00
parent ad747b1772
commit 56225bb1ad

View File

@@ -494,7 +494,7 @@ export default function Chart({
Current Current
</span> </span>
<span className="flex items-center gap-1.5"> <span className="flex items-center gap-1.5">
<span className="h-1.5 w-1.5 rounded-full border border-dashed" style={{ borderColor: 'var(--chart-axis)' }} /> <span className="h-1.5 w-1.5 rounded-full bg-neutral-300 dark:bg-neutral-600" />
Previous{prevPeriodLabel ? ` (${prevPeriodLabel})` : ''} Previous{prevPeriodLabel ? ` (${prevPeriodLabel})` : ''}
</span> </span>
</div> </div>
@@ -555,40 +555,31 @@ export default function Chart({
</div> </div>
{!hasData ? ( {!hasData ? (
<div className="flex h-72 flex-col items-center justify-center gap-2"> <div className="flex h-[250px] flex-col items-center justify-center gap-2">
<BarChartIcon className="h-10 w-10 text-neutral-200 dark:text-neutral-700" aria-hidden /> <BarChartIcon className="h-10 w-10 text-neutral-200 dark:text-neutral-700" aria-hidden />
<p className="text-sm text-neutral-400 dark:text-neutral-500">No data for this period</p> <p className="text-sm text-neutral-400 dark:text-neutral-500">No data for this period</p>
</div> </div>
) : !hasAnyNonZero ? ( ) : !hasAnyNonZero ? (
<div className="flex h-72 flex-col items-center justify-center gap-2"> <div className="flex h-[250px] flex-col items-center justify-center gap-2">
<BarChartIcon className="h-10 w-10 text-neutral-200 dark:text-neutral-700" aria-hidden /> <BarChartIcon className="h-10 w-10 text-neutral-200 dark:text-neutral-700" aria-hidden />
<p className="text-sm text-neutral-400 dark:text-neutral-500">No {metricLabel.toLowerCase()} recorded</p> <p className="text-sm text-neutral-400 dark:text-neutral-500">No {metricLabel.toLowerCase()} recorded</p>
</div> </div>
) : ( ) : (
<div className="h-[320px] w-full" onContextMenu={handleChartContextMenu}> <div className="h-[250px] w-full" onContextMenu={handleChartContextMenu}>
<ChartContainer config={dashboardChartConfig} className="h-full w-full"> <ChartContainer config={dashboardChartConfig} className="aspect-auto h-full w-full">
<BarChart accessibilityLayer data={chartData} margin={{ top: 8, right: 8, left: 0, bottom: 8 }}> <BarChart accessibilityLayer data={chartData} margin={{ left: 12, right: 12 }}>
<CartesianGrid <CartesianGrid vertical={false} />
vertical={false}
stroke="var(--chart-grid)"
strokeOpacity={0.5}
/>
<XAxis <XAxis
dataKey="date" dataKey="date"
stroke="var(--chart-axis)"
fontSize={11}
tickLine={false} tickLine={false}
axisLine={false} axisLine={false}
minTickGap={40} tickMargin={8}
ticks={midnightTicks ?? dayTicks} minTickGap={32}
dy={8}
/> />
<YAxis <YAxis
stroke="var(--chart-axis)"
fontSize={11}
tickLine={false} tickLine={false}
axisLine={false} axisLine={false}
domain={[0, 'auto']} tickMargin={8}
width={40} width={40}
allowDecimals={!isCountMetric} allowDecimals={!isCountMetric}
tickFormatter={(val) => { tickFormatter={(val) => {
@@ -607,28 +598,19 @@ export default function Chart({
prevPeriodLabel={prevPeriodLabel} prevPeriodLabel={prevPeriodLabel}
/> />
} }
cursor={false}
/> />
{hasPrev && ( {hasPrev && (
<Bar <Bar
dataKey={metric === 'visitors' ? 'prevVisitors' : metric === 'pageviews' ? 'prevPageviews' : metric === 'bounce_rate' ? 'prevBounceRate' : 'prevAvgDuration'} dataKey={metric === 'visitors' ? 'prevVisitors' : metric === 'pageviews' ? 'prevPageviews' : metric === 'bounce_rate' ? 'prevBounceRate' : 'prevAvgDuration'}
fill="var(--chart-axis)" fill="var(--chart-axis)"
fillOpacity={0.2} fillOpacity={0.15}
radius={[4, 4, 0, 0]}
isAnimationActive
animationDuration={400}
animationEasing="ease-out"
/> />
)} )}
<Bar <Bar
dataKey={metric} dataKey={metric}
fill={COLORS.brand} fill={`var(--color-${metric})`}
radius={[4, 4, 0, 0]}
isAnimationActive
animationDuration={400}
animationEasing="ease-out"
/> />
{annotationMarkers.map((marker) => { {annotationMarkers.map((marker) => {