Gauge Chart
boldkit/gauge-chartFreeComponent
Speedometer-style gauge with color zones and animated needle - custom SVG implementation
Live preview
live · rendered by the registry
Rendered by boldkit on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://boldkit.dev/r/gauge-chart.jsonSource
1/* eslint-disable react-refresh/only-export-components */2import * as React from 'react'3import { cva, type VariantProps } from 'class-variance-authority'4import { cn } from '@/lib/utils'56const gaugeChartVariants = cva(7 'relative flex items-center justify-center',8 {9 variants: {10 size: {11 sm: '',12 md: '',13 lg: '',14 },15 variant: {16 semicircle: '',17 full: '',18 meter: '',19 },20 },21 defaultVariants: {22 size: 'md',23 variant: 'semicircle',24 },25 }26)2728export interface GaugeChartZone {29 from: number30 to: number31 color: string32 label?: string33}3435export interface GaugeChartProps36 extends Omit<React.HTMLAttributes<HTMLDivElement>, 'color'>,37 VariantProps<typeof gaugeChartVariants> {38 value: number39 min?: number40 max?: number41 zones?: GaugeChartZone[]42 label?: string43 valueFormatter?: (value: number) => string44 showTicks?: boolean45 animated?: boolean46}4748const DEFAULT_ZONES: GaugeChartZone[] = [49 { from: 0, to: 33, color: 'hsl(var(--destructive))', label: 'Low' },50 { from: 33, to: 66, color: 'hsl(var(--warning))', label: 'Medium' },51 { from: 66, to: 100, color: 'hsl(var(--success))', label: 'High' },52]5354/**55 * Variant arc configs (angles in SVG space: 0°=east, increasing = clockwise, y points down):56 * semicircle — 180° sweep, arc from left (180°) over the top (270°) to right (360°), open at bottom57 * full — 360° sweep (full ring) starting at the top58 * meter — same top semicircle as semicircle but with denser tick marks (every 10%)59 */60const VARIANT_ARC_CONFIG = {61 semicircle: { arcStartDeg: 180, sweepDeg: 180 },62 full: { arcStartDeg: -90, sweepDeg: 360 }, // full 360° sweep63 meter: { arcStartDeg: 180, sweepDeg: 180 },64} as const6566type Variant = 'semicircle' | 'full' | 'meter'6768const GaugeChart = React.forwardRef<HTMLDivElement, GaugeChartProps>(69 (70 {71 value,72 min = 0,73 max = 100,74 zones = DEFAULT_ZONES,75 label,76 valueFormatter = (v) => `${v}`,77 showTicks = true,78 animated = true,79 size,80 variant,81 className,82 ...props83 },84 ref85 ) => {86 const resolvedVariant: Variant = (variant as Variant) || 'semicircle'87 const arcConfig = VARIANT_ARC_CONFIG[resolvedVariant]8889 const normalizedValue = Math.max(min, Math.min(max, value))90 const percentage = max === min ? 0 : ((normalizedValue - min) / (max - min)) * 1009192// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from boldkit
All 94 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | boldkit | Components | Free | 2 deps | |
| Alertalert | boldkit | Components | Free | 2 deps | |
| Alert Dialogalert-dialog | boldkit | Components | Free | 1 dep | |
| ASCII Shapesascii-shapes | boldkit | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | boldkit | Components | Free | 1 dep | |
| Avataravatar | boldkit | Components | Free | 1 dep | |
| Badgebadge | boldkit | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | boldkit | Components | Free | 2 deps |
