Bar Chart
scificn/bar-chartFreeComponent
CSS-only bar chart with horizontal and vertical orientations. No charting library dependency.
Live preview
live · rendered by the registry
Rendered by scificn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.scificn.dev/r/bar-chart.jsonSource
1import * as React from 'react'2import { cn } from '@/lib/utils'34export type BarChartVariant = 'DEFAULT' | 'ACTIVE' | 'WARNING' | 'CRITICAL'56export interface BarChartEntry {7 label: string8 value: number9}1011export interface BarChartProps extends React.HTMLAttributes<HTMLDivElement> {12 data: BarChartEntry[]13 orientation?: 'horizontal' | 'vertical'14 variant?: BarChartVariant15 title?: string16 showValues?: boolean17 /** Override the max value for scaling. Defaults to max(data). */18 max?: number19}2021const VERTICAL_CHART_HEIGHT = 144 // px — 9rem2223const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>(24 (25 {26 className,27 data,28 orientation = 'horizontal',29 variant = 'ACTIVE',30 title,31 showValues = true,32 max,33 style,34 ...props35 },36 ref37 ) => {38 const computedMax = max ?? Math.max(...data.map((d) => d.value), 1)3940 const accentColor =41 variant === 'ACTIVE' ? 'var(--color-green)' :42 variant === 'WARNING' ? 'var(--color-amber)' :43 variant === 'CRITICAL' ? 'var(--color-red)' :44 'var(--text-secondary)'4546 const accentGlow =47 variant === 'ACTIVE' ? 'var(--glow-green)' :48 variant === 'WARNING' ? 'var(--glow-amber)' :49 variant === 'CRITICAL' ? 'var(--glow-red)' :50 'none'5152 return (53 <div54 ref={ref}55 className={cn(className)}56 style={{57 border: '1px solid var(--border)',58 background: 'var(--surface)',59 fontFamily: 'var(--font-mono)',60 overflow: 'hidden',61 ...style,62 }}63 {...props}64 >65 {/* Title bar */}66 {title && (67 <div68 style={{69 padding: '0.4rem 0.75rem',70 borderBottom: '1px solid var(--border)',71 background: 'var(--surface-raised)',72 fontSize: '0.6rem',73 color: 'var(--text-muted)',74 letterSpacing: '0.12em',75 textTransform: 'uppercase',76 }}77 >78 {title}79 </div>80 )}8182 {orientation === 'horizontal' ? (83 /* ── Horizontal bars ── */84 <div85 style={{86 padding: '0.75rem',87 display: 'flex',88 flexDirection: 'column',89 gap: '0.5rem',90 }}91 >92 {data.map((entry, i) => {93// … truncated
More from scificn
All 33 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Alertalert | scificn | Components | Free | 1 dep | |
| Badgebadge | scificn | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | scificn | Components | Free | no deps | |
| Buttonbutton | scificn | Components | Free | 2 deps | |
| Cardcard | scificn | Components | Free | no deps | |
| Checkboxcheckbox | scificn | Components | Free | 1 dep | |
| Dialogdialog | scificn | Components | Free | 1 dep | |
| Gridgrid | scificn | Components | Free | no deps |
