Sina UI

Display

Sparkline

A trend at a glance: a thin line, and a faint area under it, that fills the width it's given. Put it under a number in a card or at the end of a table row; for a chart people read closely, use Chart.

Installation

npx sinaui add sparkline

Examples

Under a number

Each reading room's week of visits. The line takes the chart color; one value or none draws a flat hairline.

  • Baghdad 400
  • Córdoba 221
  • Fez 102
<script lang="ts">
	import Sparkline from '#lib/ui/Sparkline.svelte';

	const rooms = [
		{ name: 'Baghdad', visits: [42, 48, 45, 60, 58, 71, 76] },
		{ name: 'Córdoba', visits: [30, 28, 33, 31, 29, 34, 36] },
		{ name: 'Fez', visits: [18, 22, 16, 14, 12, 11, 9] }
	];
	const count = new Intl.NumberFormat('en-US');
</script>

<ul class="rooms">
	{#each rooms as r (r.name)}
		<li>
			<span class="name">{r.name}</span>
			<span class="num">{count.format(r.visits.reduce((a, b) => a + b, 0))}</span>
			<Sparkline values={r.visits} label="{r.name} reading-room visits, last 7 days" />
		</li>
	{/each}
</ul>

<style>
	.rooms {
		display: grid;
		gap: 1rem;
		grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
		margin: 0;
		padding: 0;
		list-style: none;
	}
	li {
		display: grid;
		gap: 0.25rem;
	}
	.name {
		color: var(--ui-muted);
		font-size: 0.8125rem;
	}
	.num {
		font-size: 1.25rem;
		font-weight: 500;
		font-variant-numeric: tabular-nums;
	}
</style>

Props

PropTypeDefault
valuesnumber[] (required), oldest first
labelstring (required): what it shows
heightnumber, in px32
areaboolean: shade under the linetrue

Accessibility

  • An image with your label as its name; say the trend in it (“rising”, “flat”), since the drawing itself isn't read.
  • Put the number it belongs to in text next to it: a sparkline adds the shape, never the only figure.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Theme toggle
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Account menu
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Sparkline
World map
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Docs navigation
Menubar
Navigation menu
Pagination
Sidebar layout
Stat tabs
Stepper
Tabs
Table of contents
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
Docs
File explorer
Messaging
Notifications
Settings
Studio
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme