Skip to content
Likable Aurora @likable-hair/svelte 5

LineChart

Line chart drawn with chart.js. Pass data as { labels, datasets: [{ label, data, color? }] }: one label per point on the horizontal axis, one value per label in every series (null leaves a gap). Lines are smooth; a series with area fills the space below it with a fading gradient, dashed draws it dashed (for example the previous year), axis: 'right' gives it a second value axis with its own format, and stacked puts the series on top of each other. Colors come from the theme (--global-color-data-1…6; when only one series has no color it gets the brand gradient with a soft glow) and follow light and dark mode and theme changes by themselves; color takes any CSS color, also var(--…). While hovering, a vertical line marks the point and the tooltip lists every series. format writes values with Intl.NumberFormat (short form on the axis, full in the tooltip). The legend appears with two or more series and hides a series on click. Drag on the chart to zoom (Ctrl + drag to pan); a "Reset zoom" icon appears in the top-right corner of the plot while zoomed, and a double click also resets the zoom. onitemclick receives the clicked point. options takes any other chart.js option and wins over the defaults. Screen readers get label and a hidden table with the values. The chart fills the height of --line-chart-height (16rem; 100% fills a sized container).

import { LineChart } from '@likable-hair/svelte';

src/lib/components/simple/charts/LineChart.svelte · Markdown for LLMs

Basic

One series takes the brand gradient of the theme with a soft glow; area fills the space below the line. While hovering, a vertical line marks the month and the tooltip shows the value written with format.

Revenue, last 12 months
Revenue
Sep€3,120
Oct€3,480
Nov€3,390
Dec€4,210
Jan€3,650
Feb€3,820
Mar€3,540
Apr€4,380
May€4,870
Jun€5,020
Jul€4,760
Aug€5,240
Code
<script lang="ts">
	import { LineChart } from '@likable-hair/svelte';

	const data = {
		labels: ['Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'],
		datasets: [
			{
				label: 'Revenue',
				data: [3120, 3480, 3390, 4210, 3650, 3820, 3540, 4380, 4870, 5020, 4760, 5240],
				area: true
			}
		]
	};
</script>

<LineChart {data} label="Revenue, last 12 months" format={{ style: 'currency', currency: 'EUR', maximumFractionDigits: 0 }} />

Comparison with last year

The current year with area, the previous one dashed in a quiet color from the theme: only the series without color takes the gradient. The legend appears because there are two series.

Revenue, this year and last year
20262025
Sep€3,120€2,810
Oct€3,480€2,950
Nov€3,390€3,100
Dec€4,210€3,600
Jan€3,650€3,240
Feb€3,820€3,300
Mar€3,540€3,180
Apr€4,380€3,560
May€4,870€3,820
Jun€5,020€3,990
Jul€4,760€3,870
Aug€5,240€4,100
Code
<script lang="ts">
	import { LineChart } from '@likable-hair/svelte';

	const data = {
		labels: ['Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'],
		datasets: [
			{ label: '2026', data: [3120, 3480, 3390, 4210, 3650, 3820, 3540, 4380, 4870, 5020, 4760, 5240], area: true },
			{
				label: '2025',
				data: [2810, 2950, 3100, 3600, 3240, 3300, 3180, 3560, 3820, 3990, 3870, 4100],
				dashed: true,
				color: 'var(--global-color-text-3)'
			}
		]
	};
</script>

<LineChart {data} label="Revenue, this year and last year" format={{ style: 'currency', currency: 'EUR', maximumFractionDigits: 0 }} />

Several series

Every series takes the next color of the data palette. A click on a legend entry hides or shows the series; the value axis adapts to the visible ones.

New customers per week by store
MilanRomeTurin
W1423518
W2483322
W3453921
W4524125
W5584024
W6614628
W7575031
W8664933
Code
<script lang="ts">
	import { LineChart } from '@likable-hair/svelte';

	const data = {
		labels: ['W1', 'W2', 'W3', 'W4', 'W5', 'W6', 'W7', 'W8'],
		datasets: [
			{ label: 'Milan', data: [42, 48, 45, 52, 58, 61, 57, 66] },
			{ label: 'Rome', data: [35, 33, 39, 41, 40, 46, 50, 49] },
			{ label: 'Turin', data: [18, 22, 21, 25, 24, 28, 31, 33] }
		]
	};
</script>

<LineChart {data} label="New customers per week by store" />

Many points and zoom

A day measured every minute: 1,440 points. Drag across the chart to zoom on a stretch of time, hold Ctrl and drag to move; the "Reset zoom" button brings back the whole day. zoom={false} turns zooming off.

Requests per minute
Requests
00:0036
00:0136
00:0236
00:0337
00:0437
00:0537
00:0637
00:0738
00:0838
00:0938
00:1038
00:1139
00:1239
00:1339
00:1439
00:1540
00:1640
00:1740
00:1840
00:1940
00:2041
00:2141
00:2241
00:2341
00:2441
00:2542
00:2642
00:2742
00:2842
00:2942
00:3043
00:3143
00:3243
00:3343
00:3443
00:3543
00:3643
00:3744
00:3844
00:3944
00:4044
00:4144
00:4244
00:4344
00:4444
00:4544
00:4644
00:4745
00:4845
00:4945
00:5045
00:5145
00:5245
00:5345
00:5445
00:5545
00:5645
00:5745
00:5845
00:5945
01:0045
01:0145
01:0245
01:0345
01:0445
01:0545
01:0645
01:0745
01:0845
01:0944
01:1044
01:1144
01:1244
01:1344
01:1444
01:1544
01:1644
01:1744
01:1843
01:1943
01:2043
01:2143
01:2243
01:2343
01:2443
01:2542
01:2642
01:2742
01:2842
01:2942
01:3041
01:3141
01:3241
01:3341
01:3441
01:3540
01:3640
01:3740
01:3840
01:3939
01:4039
01:4139
01:4239
01:4338
01:4438
01:4538
01:4637
01:4737
01:4837
01:4937
01:5036
01:5136
01:5236
01:5335
01:5435
01:5535
01:5635
01:5734
01:5834
01:5934
02:0033
02:0133
02:0233
02:0332
02:0432
02:0532
02:0632
02:0731
02:0831
02:0931
02:1030
02:1130
02:1230
02:1329
02:1429
02:1529
02:1628
02:1728
02:1828
02:1928
02:2027
02:2127
02:2227
02:2326
02:2426
02:2526
02:2626
02:2725
02:2825
02:2925
02:3024
02:3124
02:3224
02:3324
02:3423
02:3523
02:3623
02:3723
02:3822
02:3922
02:4022
02:4122
02:4222
02:4321
02:4421
02:4521
02:4621
02:4721
02:4820
02:4920
02:5020
02:5120
02:5220
02:5319
02:5419
02:5519
02:5619
02:5719
02:5819
02:5919
03:0019
03:0118
03:0218
03:0318
03:0418
03:0518
03:0618
03:0718
03:0818
03:0918
03:1018
03:1118
03:1218
03:1318
03:1418
03:1518
03:1618
03:1718
03:1818
03:1918
03:2018
03:2118
03:2218
03:2318
03:2418
03:2518
03:2618
03:2718
03:2818
03:2918
03:3018
03:3118
03:3218
03:3318
03:3418
03:3519
03:3619
03:3719
03:3819
03:3919
03:4019
03:4119
03:4219
03:4320
03:4420
03:4520
03:4620
03:4720
03:4820
03:4920
03:5021
03:5121
03:5221
03:5321
03:5421
03:5522
03:5622
03:5722
03:5822
03:5922
04:0022
04:0123
04:0223
04:0323
04:0423
04:0524
04:0624
04:0724
04:0824
04:0924
04:1025
04:1125
04:1225
04:1325
04:1425
04:1526
04:1626
04:1726
04:1826
04:1927
04:2027
04:2127
04:2227
04:2327
04:2428
04:2528
04:2628
04:2728
04:2828
04:2929
04:3029
04:3129
04:3229
04:3329
04:3430
04:3530
04:3630
04:3730
04:3830
04:3931
04:4031
04:4131
04:4231
04:4331
04:4431
04:4532
04:4632
04:4732
04:4832
04:4932
04:5032
04:5132
04:5233
04:5333
04:5433
04:5533
04:5633
04:5733
04:5833
04:5933
05:0033
05:0133
05:0234
05:0334
05:0434
05:0534
05:0634
05:0734
05:0834
05:0934
05:1034
05:1134
05:1234
05:1334
05:1434
05:1534
05:1634
05:1734
05:1834
05:1934
05:2034
05:2134
05:2234
05:2334
05:2434
05:2534
05:2634
05:2734
05:2834
05:2934
05:3033
05:3133
05:3233
05:3333
05:3433
05:3533
05:3633
05:3733
05:3833
05:3933
05:4032
05:4132
05:4232
05:4332
05:4432
05:4532
05:4632
05:4731
05:4831
05:4931
05:5031
05:5131
05:5231
05:5330
05:5430
05:5530
05:5630
05:5730
05:5829
05:5929
06:0029
06:0129
06:0230
06:0330
06:0431
06:0531
06:0631
06:0732
06:0832
06:0932
06:1033
06:1133
06:1233
06:1334
06:1434
06:1534
06:1635
06:1735
06:1835
06:1936
06:2036
06:2136
06:2237
06:2337
06:2437
06:2538
06:2638
06:2739
06:2839
06:2939
06:3040
06:3140
06:3240
06:3341
06:3441
06:3541
06:3642
06:3742
06:3843
06:3943
06:4043
06:4144
06:4244
06:4345
06:4445
06:4545
06:4646
06:4746
06:4847
06:4947
06:5048
06:5148
06:5248
06:5349
06:5449
06:5550
06:5650
06:5751
06:5851
06:5952
07:0052
07:0153
07:0253
07:0354
07:0454
07:0555
07:0655
07:0756
07:0856
07:0957
07:1057
07:1158
07:1258
07:1359
07:1459
07:1560
07:1661
07:1761
07:1862
07:1962
07:2063
07:2164
07:2264
07:2365
07:2465
07:2566
07:2667
07:2767
07:2868
07:2969
07:3069
07:3170
07:3271
07:3371
07:3472
07:3573
07:3673
07:3774
07:3875
07:3975
07:4076
07:4177
07:4277
07:4378
07:4479
07:4580
07:4680
07:4781
07:4882
07:4983
07:5083
07:5184
07:5285
07:5386
07:5486
07:5587
07:5688
07:5789
07:5890
07:5990
08:0091
08:0192
08:0293
08:0393
08:0494
08:0595
08:0696
08:0797
08:0897
08:0998
08:1099
08:11100
08:12101
08:13101
08:14102
08:15103
08:16104
08:17105
08:18105
08:19106
08:20107
08:21108
08:22109
08:23110
08:24110
08:25111
08:26112
08:27113
08:28113
08:29114
08:30115
08:31116
08:32117
08:33117
08:34118
08:35119
08:36120
08:37121
08:38121
08:39122
08:40123
08:41124
08:42124
08:43125
08:44126
08:45127
08:46127
08:47128
08:48129
08:49129
08:50130
08:51131
08:52132
08:53132
08:54133
08:55134
08:56134
08:57135
08:58136
08:59136
09:00137
09:01138
09:02138
09:03139
09:04140
09:05140
09:06141
09:07141
09:08142
09:09143
09:10143
09:11144
09:12144
09:13145
09:14145
09:15146
09:16147
09:17147
09:18148
09:19148
09:20149
09:21149
09:22150
09:23150
09:24151
09:25151
09:26152
09:27152
09:28152
09:29153
09:30153
09:31154
09:32154
09:33155
09:34155
09:35155
09:36156
09:37156
09:38156
09:39157
09:40157
09:41158
09:42158
09:43158
09:44158
09:45159
09:46159
09:47159
09:48160
09:49160
09:50160
09:51161
09:52161
09:53161
09:54161
09:55162
09:56162
09:57162
09:58162
09:59162
10:00163
10:01163
10:02163
10:03163
10:04163
10:05164
10:06164
10:07164
10:08164
10:09164
10:10164
10:11165
10:12165
10:13165
10:14165
10:15165
10:16165
10:17165
10:18166
10:19166
10:20166
10:21166
10:22166
10:23166
10:24166
10:25166
10:26166
10:27167
10:28167
10:29167
10:30167
10:31167
10:32167
10:33167
10:34167
10:35167
10:36167
10:37167
10:38168
10:39168
10:40168
10:41168
10:42168
10:43168
10:44168
10:45168
10:46168
10:47168
10:48168
10:49168
10:50169
10:51169
10:52169
10:53169
10:54169
10:55169
10:56169
10:57169
10:58169
10:59169
11:00169
11:01170
11:02170
11:03170
11:04170
11:05170
11:06170
11:07170
11:08170
11:09170
11:10171
11:11171
11:12171
11:13171
11:14171
11:15171
11:16171
11:17172
11:18172
11:19172
11:20172
11:21172
11:22172
11:23173
11:24173
11:25173
11:26173
11:27173
11:28174
11:29174
11:30174
11:31174
11:32174
11:33175
11:34175
11:35175
11:36175
11:37176
11:38176
11:39176
11:40176
11:41177
11:42177
11:43177
11:44177
11:45178
11:46178
11:47178
11:48178
11:49179
11:50179
11:51179
11:52180
11:53180
11:54180
11:55180
11:56181
11:57181
11:58181
11:59182
12:00182
12:01182
12:02183
12:03183
12:04183
12:05184
12:06184
12:07184
12:08185
12:09185
12:10185
12:11186
12:12186
12:13186
12:14187
12:15187
12:16187
12:17188
12:18188
12:19189
12:20189
12:21189
12:22190
12:23190
12:24190
12:25191
12:26191
12:27191
12:28192
12:29192
12:30192
12:31193
12:32193
12:33193
12:34194
12:35194
12:36194
12:37195
12:38195
12:39195
12:40196
12:41196
12:42196
12:43197
12:44197
12:45197
12:46198
12:47198
12:48198
12:49199
12:50199
12:51199
12:52200
12:53200
12:54200
12:55200
12:56201
12:57201
12:58201
12:59201
13:00202
13:01202
13:02202
13:03202
13:04203
13:05203
13:06203
13:07203
13:08203
13:09204
13:10204
13:11204
13:12204
13:13204
13:14205
13:15205
13:16205
13:17205
13:18205
13:19205
13:20205
13:21205
13:22206
13:23206
13:24206
13:25206
13:26206
13:27206
13:28206
13:29206
13:30206
13:31206
13:32206
13:33206
13:34206
13:35206
13:36206
13:37206
13:38206
13:39206
13:40206
13:41206
13:42206
13:43206
13:44206
13:45206
13:46206
13:47206
13:48206
13:49206
13:50205
13:51205
13:52205
13:53205
13:54205
13:55205
13:56205
13:57205
13:58204
13:59204
14:00204
14:01204
14:02204
14:03203
14:04203
14:05203
14:06203
14:07203
14:08202
14:09202
14:10202
14:11202
14:12201
14:13201
14:14201
14:15201
14:16200
14:17200
14:18200
14:19200
14:20199
14:21199
14:22199
14:23198
14:24198
14:25198
14:26197
14:27197
14:28197
14:29197
14:30196
14:31196
14:32196
14:33195
14:34195
14:35195
14:36194
14:37194
14:38194
14:39193
14:40193
14:41192
14:42192
14:43192
14:44191
14:45191
14:46191
14:47190
14:48190
14:49190
14:50189
14:51189
14:52189
14:53188
14:54188
14:55188
14:56187
14:57187
14:58187
14:59186
15:00186
15:01186
15:02185
15:03185
15:04185
15:05184
15:06184
15:07184
15:08183
15:09183
15:10183
15:11182
15:12182
15:13182
15:14181
15:15181
15:16181
15:17181
15:18180
15:19180
15:20180
15:21179
15:22179
15:23179
15:24179
15:25178
15:26178
15:27178
15:28178
15:29177
15:30177
15:31177
15:32177
15:33177
15:34176
15:35176
15:36176
15:37176
15:38176
15:39175
15:40175
15:41175
15:42175
15:43175
15:44175
15:45174
15:46174
15:47174
15:48174
15:49174
15:50174
15:51174
15:52173
15:53173
15:54173
15:55173
15:56173
15:57173
15:58173
15:59173
16:00173
16:01173
16:02173
16:03172
16:04172
16:05172
16:06172
16:07172
16:08172
16:09172
16:10172
16:11172
16:12172
16:13172
16:14172
16:15172
16:16172
16:17172
16:18172
16:19172
16:20172
16:21172
16:22172
16:23172
16:24172
16:25172
16:26172
16:27172
16:28172
16:29172
16:30172
16:31172
16:32172
16:33172
16:34172
16:35172
16:36172
16:37172
16:38172
16:39172
16:40172
16:41172
16:42172
16:43172
16:44172
16:45172
16:46172
16:47172
16:48172
16:49172
16:50172
16:51172
16:52172
16:53172
16:54172
16:55172
16:56172
16:57172
16:58172
16:59172
17:00172
17:01172
17:02172
17:03172
17:04172
17:05172
17:06172
17:07172
17:08172
17:09172
17:10172
17:11172
17:12172
17:13172
17:14171
17:15171
17:16171
17:17171
17:18171
17:19171
17:20171
17:21171
17:22171
17:23170
17:24170
17:25170
17:26170
17:27170
17:28170
17:29170
17:30169
17:31169
17:32169
17:33169
17:34169
17:35168
17:36168
17:37168
17:38168
17:39167
17:40167
17:41167
17:42167
17:43166
17:44166
17:45166
17:46166
17:47165
17:48165
17:49165
17:50164
17:51164
17:52164
17:53163
17:54163
17:55163
17:56162
17:57162
17:58161
17:59161
18:00161
18:01160
18:02160
18:03159
18:04159
18:05158
18:06158
18:07158
18:08157
18:09157
18:10156
18:11156
18:12155
18:13155
18:14154
18:15154
18:16153
18:17153
18:18152
18:19152
18:20151
18:21151
18:22150
18:23149
18:24149
18:25148
18:26148
18:27147
18:28147
18:29146
18:30145
18:31145
18:32144
18:33144
18:34143
18:35142
18:36142
18:37141
18:38141
18:39140
18:40139
18:41139
18:42138
18:43137
18:44137
18:45136
18:46136
18:47135
18:48134
18:49134
18:50133
18:51132
18:52132
18:53131
18:54130
18:55130
18:56129
18:57128
18:58128
18:59127
19:00126
19:01126
19:02125
19:03124
19:04124
19:05123
19:06122
19:07122
19:08121
19:09120
19:10120
19:11119
19:12118
19:13118
19:14117
19:15116
19:16116
19:17115
19:18115
19:19114
19:20113
19:21113
19:22112
19:23111
19:24111
19:25110
19:26110
19:27109
19:28108
19:29108
19:30107
19:31107
19:32106
19:33105
19:34105
19:35104
19:36104
19:37103
19:38102
19:39102
19:40101
19:41101
19:42100
19:43100
19:4499
19:4599
19:4698
19:4797
19:4897
19:4996
19:5096
19:5195
19:5295
19:5394
19:5494
19:5593
19:5693
19:5792
19:5892
19:5992
20:0091
20:0191
20:0290
20:0390
20:0489
20:0589
20:0688
20:0788
20:0888
20:0987
20:1087
20:1186
20:1286
20:1385
20:1485
20:1585
20:1684
20:1784
20:1883
20:1983
20:2083
20:2182
20:2282
20:2382
20:2481
20:2581
20:2681
20:2780
20:2880
20:2979
20:3079
20:3179
20:3278
20:3378
20:3478
20:3577
20:3677
20:3777
20:3876
20:3976
20:4076
20:4175
20:4275
20:4375
20:4475
20:4574
20:4674
20:4774
20:4873
20:4973
20:5073
20:5172
20:5272
20:5372
20:5471
20:5571
20:5671
20:5770
20:5870
20:5970
21:0069
21:0169
21:0269
21:0369
21:0468
21:0568
21:0668
21:0767
21:0867
21:0967
21:1066
21:1166
21:1265
21:1365
21:1465
21:1564
21:1664
21:1764
21:1863
21:1963
21:2063
21:2162
21:2262
21:2361
21:2461
21:2561
21:2660
21:2760
21:2859
21:2959
21:3059
21:3158
21:3258
21:3357
21:3457
21:3556
21:3656
21:3755
21:3855
21:3954
21:4054
21:4153
21:4253
21:4353
21:4452
21:4551
21:4651
21:4750
21:4850
21:4949
21:5049
21:5148
21:5248
21:5347
21:5447
21:5546
21:5645
21:5745
21:5844
21:5944
22:0043
22:0143
22:0243
22:0343
22:0443
22:0543
22:0643
22:0742
22:0842
22:0942
22:1042
22:1142
22:1242
22:1342
22:1442
22:1541
22:1641
22:1741
22:1841
22:1941
22:2041
22:2140
22:2240
22:2340
22:2440
22:2540
22:2639
22:2739
22:2839
22:2939
22:3039
22:3138
22:3238
22:3338
22:3438
22:3537
22:3637
22:3737
22:3837
22:3936
22:4036
22:4136
22:4235
22:4335
22:4435
22:4535
22:4634
22:4734
22:4834
22:4933
22:5033
22:5133
22:5233
22:5332
22:5432
22:5532
22:5631
22:5731
22:5831
22:5930
23:0030
23:0130
23:0229
23:0329
23:0429
23:0528
23:0628
23:0728
23:0828
23:0927
23:1027
23:1127
23:1226
23:1326
23:1426
23:1525
23:1625
23:1725
23:1825
23:1924
23:2024
23:2124
23:2223
23:2323
23:2423
23:2523
23:2622
23:2722
23:2822
23:2922
23:3021
23:3121
23:3221
23:3321
23:3420
23:3520
23:3620
23:3720
23:3819
23:3919
23:4019
23:4119
23:4219
23:4318
23:4418
23:4518
23:4618
23:4718
23:4818
23:4917
23:5017
23:5117
23:5217
23:5317
23:5417
23:5517
23:5617
23:5716
23:5816
23:5916
Code
<script lang="ts">
	import { LineChart } from '@likable-hair/svelte';

	const labels = Array.from({ length: 1440 }, (_, i) => `${String(Math.floor(i / 60)).padStart(2, '0')}:${String(i % 60).padStart(2, '0')}`);
	const values = labels.map((_, i) => {
		const hour = i / 60;
		const day = Math.max(0, Math.sin(((hour - 6) / 16) * Math.PI));
		return Math.round(30 + day * 170 + Math.sin(i / 40) * 10 + Math.cos(i / 97) * 6);
	});
	const data = { labels, datasets: [{ label: 'Requests', data: values }] };
</script>

<LineChart {data} label="Requests per minute" />

Custom tooltip

tooltipSnippet replaces the content of the tooltip; it receives the title and one item per series with the formatted value, the raw number and the color. The card around it stays the one of the library.

Bookings per day
Bookings
Mon38
Tue44
Wed41
Thu56
Fri63
Sat71
Sun29
Code
<script lang="ts">
	import { LineChart } from '@likable-hair/svelte';

	const target = 50;
	const data = {
		labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
		datasets: [{ label: 'Bookings', data: [38, 44, 41, 56, 63, 71, 29] }]
	};
</script>

<LineChart {data} label="Bookings per day">
	{#snippet tooltipSnippet({ title, items })}
		<strong>{title}</strong>
		{#each items as item (item.datasetIndex)}
			<span>{item.value} bookings · {(item.raw ?? 0) >= target ? 'above' : 'below'} target</span>
		{/each}
	{/snippet}
</LineChart>

Props

NameTypeDefaultDescription
data requiredChartDataThe labels of the horizontal axis (labels) and the series (datasets), with one value per label. Svelte state can be passed as it is.
label stringName of the chart for screen readers, also the caption of the hidden table of values.
stacked booleanfalsePuts the series on top of each other.
format ChartFormatHow values are written: options of Intl.NumberFormat (for example { style: 'currency', currency: 'EUR' }) or a function. Axes use the short form (€1.2M). A series can have its own format.
legend 'auto' | false | 'top' | 'bottom' | 'right''auto'Where the legend goes. auto shows it below the chart when there are two or more series.
zoom booleantrueDrag on the chart to zoom on the horizontal axis, Ctrl + drag to pan; a "Reset zoom" icon appears in the top-right corner of the plot while zoomed, and a double click also resets the zoom.
options ChartOptions<'line'>Any other chart.js option, merged over the defaults of the library (for example scales.y.min, scales.y.type: 'logarithmic').
locale stringBCP 47 locale of the texts and of the numbers (it and en are built in, other languages fall back to English). Defaults to the one set with setDefaultLocale, else en.
resetZoomLabel stringText of the button that resets the zoom. Defaults to "Reset zoom", in the language of locale.
chart bindable ChartThe chart.js instance, to call its methods (resetZoom(), toBase64Image()).
lineChartElement bindable HTMLDivElementThe root <div> element.
class string''Extra classes on the root <div> element.

It also accepts the native attributes and events of <div> (for example id, title, aria-label, onkeydown), which are forwarded to the element.

Snippets

NameParametersDescription
tooltipSnippetChartTooltipReplaces the content of the tooltip.
legendSnippet{ items: ChartLegendItem[]; toggle: (key: string) => void }Replaces the legend; toggle(key) hides or shows a series.

Events

NameTypeDescription
onitemclick(item: ChartItemClick) => voidCalled with the point clicked; the pointer becomes a hand over the points.

Types

Exported by the package: import type { ChartData, ChartFormat, ChartTooltip, ChartLegendItem, ChartItemClick, ChartSeries, ChartTooltipItem } from '@likable-hair/svelte';

ChartData

The data of a chart: the labels of the categories and the series. Same shape as the data of chart.js.

interface ChartData

NameTypeDescription
labels requiredstring[]One label per category: months, products, countries.
datasets requiredChartSeries[]The series, drawn in order.

ChartFormat

How values are written: options of Intl.NumberFormat (in the chart's locale), or a function. Axes write numbers in short form (€1.2M), tooltips in full.

type ChartFormat = Intl.NumberFormatOptions | ((value: number) => string)

ChartTooltip

What the tooltip shows.

interface ChartTooltip

NameTypeDescription
title requiredstringThe label of the category.
items requiredChartTooltipItem[]One row per series (one in a PieChart).

ChartLegendItem

One entry of the legend: a series, or a slice in a PieChart.

interface ChartLegendItem

NameTypeDescription
key requiredstringStable key of the entry.
label requiredstringName shown.
color requiredstringCSS color of the swatch (can be a gradient).
hidden requiredbooleanThe series or slice is hidden.
detail stringExtra text after the name, for example the share of a slice.

ChartItemClick

The value clicked in a chart.

interface ChartItemClick

NameTypeDescription
index requirednumberPosition of the value in data, the same as its label in labels.
datasetIndex requirednumberPosition of the series in datasets.
label requiredstringThe label of the category.
value requirednumber | nullThe value as in the data.
event requiredMouseEventThe native click event.

ChartSeries

One series of a chart: the values, one per label, and how they are drawn. Any other key of a chart.js dataset passes through unchanged (for example borderWidth, pointStyle, order).

interface ChartSeries

NameTypeDescription
label stringName of the series, in the legend, the tooltip and the table read by screen readers.
data required(number | null)[]One value per label; null leaves a gap.
color string | string[]Any CSS color, also var(--…), light-dark() and color-mix(); an array gives one color per bar or slice. Defaults to the data palette of the theme (--global-color-data-1…6).
type 'bar' | 'line'In a BarChart, line draws this series as a line over the bars.
axis 'left' | 'right'right puts the series on a second value axis on the right (at the top in a horizontal chart), with its own scale and format.
format ChartFormatFormat of this series, instead of the chart's format.
dashed booleanDraws the line dashed, for example a comparison with the previous year.
area booleanFills the area under the line with a fading gradient.

ChartTooltipItem

One row of the tooltip.

interface ChartTooltipItem

NameTypeDescription
label requiredstringName of the series (empty in a PieChart).
value requiredstringThe value, already formatted.
raw requirednumber | nullThe value as in the data.
color requiredstringCSS color of the series or slice.
datasetIndex requirednumberPosition of the series in datasets.
index requirednumberPosition of the value in data, the same as its label in labels.

CSS variables

For a single instance, pass them as style props: <LineChart --line-chart-grid-color="tomato">. The --line-chart-default-* defaults apply to the whole app: override them in :root or in a theme.

Per-instance variableDefault
--line-chart-width
--line-chart-default-width 100%
--line-chart-min-width
--line-chart-default-min-width 12rem
--line-chart-height
--line-chart-default-height 16rem
--line-chart-gap
--line-chart-default-gap 12px
--line-chart-grid-color
--line-chart-default-grid-color var(--global-color-border)
--line-chart-tick-color
--line-chart-default-tick-color var(--global-color-text-3)
--line-chart-tick-font-family
--line-chart-default-tick-font-family var(--global-font-family-mono)
--line-chart-tick-font-size
--line-chart-default-tick-font-size 11px
--line-chart-line-width
--line-chart-default-line-width 3px
--line-chart-gradient-from
--line-chart-default-gradient-from var(--global-color-data-1)
--line-chart-gradient-via
--line-chart-default-gradient-via var(--global-color-data-3)
--line-chart-gradient-to
--line-chart-default-gradient-to var(--global-color-data-2)
--line-chart-glow-color
--line-chart-default-glow-color var(--global-color-primary-glow)
--line-chart-glow-blur
--line-chart-default-glow-blur 10px
--line-chart-point-background
--line-chart-default-point-background var(--global-color-surface-pop)
--line-chart-crosshair-color
--line-chart-default-crosshair-color var(--global-color-border-strong)
--line-chart-reset-background
--line-chart-default-reset-background var(--global-color-surface-pop)
--line-chart-zoom-color
--line-chart-default-zoom-color var(--global-color-primary)
--line-chart-legend-gap
--line-chart-default-legend-gap 16px
--line-chart-legend-font-size
--line-chart-default-legend-font-size 12.5px
--line-chart-legend-color
--line-chart-default-legend-color var(--global-color-text-2)
--line-chart-legend-swatch-size
--line-chart-default-legend-swatch-size 8px
--line-chart-legend-swatch-radius
--line-chart-default-legend-swatch-radius 2px
--line-chart-legend-hidden-opacity
--line-chart-default-legend-hidden-opacity 0.45
--line-chart-legend-detail-color
--line-chart-default-legend-detail-color var(--global-color-text)
--line-chart-legend-detail-font-family
--line-chart-default-legend-detail-font-family var(--global-font-family-mono)
--line-chart-legend-min-width
--line-chart-default-legend-min-width 180px
--line-chart-tooltip-background
--line-chart-default-tooltip-background var(--global-color-surface-pop)
--line-chart-tooltip-border-color
--line-chart-default-tooltip-border-color var(--global-color-border-strong)
--line-chart-tooltip-border-width
--line-chart-default-tooltip-border-width var(--global-border-width)
--line-chart-tooltip-radius
--line-chart-default-tooltip-radius var(--global-radius-lg)
--line-chart-tooltip-shadow
--line-chart-default-tooltip-shadow var(--global-shadow-md)
--line-chart-tooltip-padding
--line-chart-default-tooltip-padding 8px 12px
--line-chart-tooltip-min-width
--line-chart-default-tooltip-min-width auto
--line-chart-tooltip-color
--line-chart-default-tooltip-color var(--global-color-text)
--line-chart-tooltip-title-color
--line-chart-default-tooltip-title-color var(--global-color-text-3)
--line-chart-tooltip-title-font-family
--line-chart-default-tooltip-title-font-family var(--global-font-family-mono)
--line-chart-tooltip-title-font-size
--line-chart-default-tooltip-title-font-size 10.5px
--line-chart-tooltip-label-color
--line-chart-default-tooltip-label-color var(--global-color-text-2)
--line-chart-tooltip-label-font-size
--line-chart-default-tooltip-label-font-size 12px
--line-chart-tooltip-value-font-family
--line-chart-default-tooltip-value-font-family var(--global-font-family-display)
--line-chart-tooltip-value-font-size
--line-chart-default-tooltip-value-font-size 13px