Skip to main content
Tw Twintrinsic
  • Getting Started
  • Components
  • Theming
  • Completion
Examples
Data Dashboard Game Map
Core
App
Layout
Accordion AccordionItem Card Container Panel Separator Sidebar Splitter
Navigation
AppHeader BottomBar Breadcrumb BreadcrumbItem Menu MenuItem Tabs Tab TabList TabPanel TreeMenu
Data Display
Avatar AvatarGroup Badge Carousel CarouselItem Chip ChipGroup CodeBlock CodeBlockSpeed CodeEditor DataTable Map Progress Skeleton Table TableBody TableCell TableHead TableHeader TableRow Tag TagGroup Timeline TimelineItem Tooltip Tree TreeNode
Metrics
DonutChart PieChart LineChart BarChart HorizontalBarChart AreaChart StatsCard MetricGrid KPICard GaugeChart ProgressMetric MetricTrend
Form
AutoComplete Button ButtonGroup Calendar Checkbox ColorPicker Combobox Dropdown FileUpload FloatLabel Form FormField Input InputSwitch InvalidState Knob ListInput Listbox NumberInput Radio RadioGroup Rating Select SelectGroup Slider Switch TextInput Textarea
Feedback
Modal Stepper StepperStep Toast
Utility
Icon Lazy LazyPanel Masonry ThemeToggle

BarChart

A vertical bar chart for comparing values across categories. Supports single and multiple data series with grid lines and axis labels.

Features

  • Single and multiple data series support
  • Grouped bars for comparison
  • Grid lines for reference
  • Axis labels and title
  • Legend display
  • Interactive bars with click events
  • Responsive sizing
  • Accessible with ARIA labels

Examples

Single Series BarChart

Monthly Revenue

017345067JanFebMarAprMayJun
Revenue
<script>
  import { BarChart } from '$lib';

  const series = [
    {
      label: 'Revenue',
      data: [45, 52, 48, 61, 55, 67],
      color: '#3b82f6'
    }
  ];
  const labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'];
</script>

<BarChart {series} {labels} title="Monthly Revenue" width={600} height={300} />

Multiple Series BarChart

Quarterly Comparison

014284155Product AProduct BProduct CProduct DSales ($K)
Q1
Q2
<BarChart
  series={[
    { label: 'Q1', data: [30, 40, 35, 50], color: '#3b82f6' },
    { label: 'Q2', data: [35, 45, 40, 55], color: '#ef4444' }
  ]}
  labels={['Product A', 'Product B', 'Product C', 'Product D']}
  title="Quarterly Comparison"
  yAxisLabel="Sales ($K)"
  showGrid={true}
  showLegend={true}
  width={600}
  height={300}
/>

Props

PropTypeDefaultDescription
seriesSeries[]RequiredArray of data series with label, data, and optional color
labelsstring[]RequiredArray of category labels
titlestringundefinedChart title
yAxisLabelstringundefinedY-axis label
showGridbooleantrueShow grid lines
showLegendbooleantrueShow legend
widthnumber500Chart width in pixels
heightnumber300Chart height in pixels

Events

EventDetailDescription
onbarclick{ seriesIndex: number; barIndex: number; value: number }Fired when a bar is clicked

Accessibility

  • SVG has proper ARIA role and label
  • Bars are keyboard accessible
  • Color contrast meets WCAG AA standards
  • Legend provides text alternative to colors
  • Grid lines aid in reading values

Best Practices

  • Use for comparing values across categories
  • Limit to 3-4 series for clarity
  • Use distinct colors for each series
  • Include axis labels for context
  • Enable grid lines for easier value reading