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

LineChart

A line graph for displaying trends over time. Supports single and multiple data series with smooth curves, grid lines, and axis labels.

Features

  • Single and multiple data series support
  • Smooth curve rendering
  • Grid lines for reference
  • Axis labels and title
  • Legend display
  • Interactive points with click events
  • Responsive sizing
  • Accessible with ARIA labels

Examples

Single Series LineChart

Weekly Sales

06131925MonTueWedThuFriSatSun
Sales
<script>
  import { LineChart } from '$lib';

  const series = [
    {
      label: 'Sales',
      data: [10, 15, 12, 18, 22, 20, 25],
      color: '#3b82f6'
    }
  ];
  const labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
</script>

<LineChart {series} {labels} title="Weekly Sales" width={600} height={300} />

Multiple Series LineChart

Product Comparison

06131925MonTueWedThuFriSatSunSales ($K)
Product A
Product B
<LineChart
  series={[
    { label: 'Product A', data: [10, 15, 12, 18, 22, 20, 25], color: '#3b82f6' },
    { label: 'Product B', data: [8, 12, 14, 16, 18, 22, 20], color: '#ef4444' }
  ]}
  labels={['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']}
  title="Product 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 x-axis labels
titlestringundefinedChart title
yAxisLabelstringundefinedY-axis label
showGridbooleantrueShow grid lines
showLegendbooleantrueShow legend
widthnumber500Chart width in pixels
heightnumber300Chart height in pixels

Events

EventDetailDescription
onpointclick{ seriesIndex: number; pointIndex: number; value: number }Fired when a data point is clicked

Accessibility

  • SVG has proper ARIA role and label
  • Data points 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 showing trends over time
  • 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