Chart
Bar, line, area, pie and donut charts drawn in your theme, stacked or smooth, with a legend, tooltips and a data table for screen readers. Same markup and props in every style: switch the style in the header to see it change.
Bar
Two series side by side. Hover a month, or focus the chart and use the arrow keys, to see its values. In HTML the SVG is static; add data-vin-chart and include vinui.js for the tooltip.
<div class="vin-chart vin-chart--bar" data-vin-chart style="--vin-chart-axis:4ch;max-width:560px">
<div class="vin-chart__legend" aria-hidden="true">
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-1)"></span>Desktop</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-2)"></span>Mobile</span>
</div>
<div class="vin-chart__body">
<div class="vin-chart__y" aria-hidden="true">
<span class="vin-chart__tick" style="top:100%">0</span>
<span class="vin-chart__tick" style="top:75%">100</span>
<span class="vin-chart__tick" style="top:50%">200</span>
<span class="vin-chart__tick" style="top:25%">300</span>
<span class="vin-chart__tick" style="top:0%">400</span>
</div>
<div class="vin-chart__plot">
<svg class="vin-chart__svg" viewBox="0 0 600 250" role="img" aria-label="Visitors by month, January to June (bar chart)" tabindex="0">
<path class="vin-chart__grid" d="M0 187.5H600M0 125H600M0 62.5H600M0 0H600" />
<rect class="vin-chart__hit" data-i="0" x="0" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="1" x="100" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="2" x="200" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="3" x="300" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="4" x="400" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="5" x="500" y="0" width="100" height="250" />
<g class="vin-chart__series" style="--vin-series:var(--vin-chart-1)">
<rect class="vin-chart__bar" data-i="0" x="14" y="133.75" width="34" height="116.25" />
<rect class="vin-chart__bar" data-i="1" x="114" y="59.38" width="34" height="190.62" />
<rect class="vin-chart__bar" data-i="2" x="214" y="101.88" width="34" height="148.12" />
<rect class="vin-chart__bar" data-i="3" x="314" y="204.38" width="34" height="45.62" />
<rect class="vin-chart__bar" data-i="4" x="414" y="119.38" width="34" height="130.62" />
<rect class="vin-chart__bar" data-i="5" x="514" y="116.25" width="34" height="133.75" />
</g>
<g class="vin-chart__series" style="--vin-series:var(--vin-chart-2)">
<rect class="vin-chart__bar" data-i="0" x="52" y="200" width="34" height="50" />
<rect class="vin-chart__bar" data-i="1" x="152" y="125" width="34" height="125" />
<rect class="vin-chart__bar" data-i="2" x="252" y="175" width="34" height="75" />
<rect class="vin-chart__bar" data-i="3" x="352" y="131.25" width="34" height="118.75" />
<rect class="vin-chart__bar" data-i="4" x="452" y="168.75" width="34" height="81.25" />
<rect class="vin-chart__bar" data-i="5" x="552" y="162.5" width="34" height="87.5" />
</g>
<path class="vin-chart__axis" d="M0 250H600" />
</svg>
</div>
<div class="vin-chart__x" aria-hidden="true">
<span class="vin-chart__tick" style="left:8.33%">Jan</span>
<span class="vin-chart__tick" style="left:25%">Feb</span>
<span class="vin-chart__tick" style="left:41.67%">Mar</span>
<span class="vin-chart__tick" style="left:58.33%">Apr</span>
<span class="vin-chart__tick" style="left:75%">May</span>
<span class="vin-chart__tick" style="left:91.67%">Jun</span>
</div>
</div>
<table class="vin-chart__table">
<caption>Visitors by month, January to June</caption>
<thead>
<tr><th scope="col">Month</th><th scope="col">Desktop</th><th scope="col">Mobile</th></tr>
</thead>
<tbody>
<tr><th scope="row">Jan</th><td>186</td><td>80</td></tr>
<tr><th scope="row">Feb</th><td>305</td><td>200</td></tr>
<tr><th scope="row">Mar</th><td>237</td><td>120</td></tr>
<tr><th scope="row">Apr</th><td>73</td><td>190</td></tr>
<tr><th scope="row">May</th><td>209</td><td>130</td></tr>
<tr><th scope="row">Jun</th><td>214</td><td>140</td></tr>
</tbody>
</table>
</div>import { Chart } from "@/components/vin/chart";
const visitors = [
{ month: "Jan", desktop: 186, mobile: 80 },
{ month: "Feb", desktop: 305, mobile: 200 },
{ month: "Mar", desktop: 237, mobile: 120 },
{ month: "Apr", desktop: 73, mobile: 190 },
{ month: "May", desktop: 209, mobile: 130 },
{ month: "Jun", desktop: 214, mobile: 140 },
];
export function ChartBar() {
return (
<Chart
type="bar"
label="Visitors by month, January to June"
data={visitors}
index="month"
indexLabel="Month"
series={[{ key: "desktop", label: "Desktop" }, { key: "mobile", label: "Mobile" }]}
style={{ maxWidth: 560 }}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Chart from "@/components/vin/chart.vue";
const visitors = [
{ month: "Jan", desktop: 186, mobile: 80 },
{ month: "Feb", desktop: 305, mobile: 200 },
{ month: "Mar", desktop: 237, mobile: 120 },
{ month: "Apr", desktop: 73, mobile: 190 },
{ month: "May", desktop: 209, mobile: 130 },
{ month: "Jun", desktop: 214, mobile: 140 },
];
</script>
<template>
<Chart
type="bar"
label="Visitors by month, January to June"
:data="visitors"
index="month"
index-label="Month"
:series="[{ key: 'desktop', label: 'Desktop' }, { key: 'mobile', label: 'Mobile' }]"
style="max-width: 560px"
/>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Chart from "$lib/components/vin/chart.svelte";
const visitors = [
{ month: "Jan", desktop: 186, mobile: 80 },
{ month: "Feb", desktop: 305, mobile: 200 },
{ month: "Mar", desktop: 237, mobile: 120 },
{ month: "Apr", desktop: 73, mobile: 190 },
{ month: "May", desktop: 209, mobile: 130 },
{ month: "Jun", desktop: 214, mobile: 140 },
];
</script>
<Chart
type="bar"
label="Visitors by month, January to June"
data={visitors}
index="month"
indexLabel="Month"
series={[
{ key: "desktop", label: "Desktop" },
{ key: "mobile", label: "Mobile" },
]}
style="max-width: 560px"
/>Line
This week against last week, with a point on each day.
| Day | This week | Last week |
|---|---|---|
| Mon | 42 | 35 |
| Tue | 58 | 41 |
| Wed | 51 | 49 |
| Thu | 73 | 52 |
| Fri | 69 | 61 |
| Sat | 38 | 30 |
| Sun | 31 | 24 |
<div class="vin-chart vin-chart--line" data-vin-chart style="--vin-chart-axis:3ch;max-width:560px">
<div class="vin-chart__legend" aria-hidden="true">
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-1)"></span>This week</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-2)"></span>Last week</span>
</div>
<div class="vin-chart__body">
<div class="vin-chart__y" aria-hidden="true">
<span class="vin-chart__tick" style="top:100%">0</span>
<span class="vin-chart__tick" style="top:75%">20</span>
<span class="vin-chart__tick" style="top:50%">40</span>
<span class="vin-chart__tick" style="top:25%">60</span>
<span class="vin-chart__tick" style="top:0%">80</span>
</div>
<div class="vin-chart__plot">
<svg class="vin-chart__svg" viewBox="0 0 600 250" role="img" aria-label="Signups per day, this week and last week (line chart)" tabindex="0">
<path class="vin-chart__grid" d="M0 187.5H600M0 125H600M0 62.5H600M0 0H600" />
<rect class="vin-chart__hit" data-i="0" x="0" y="0" width="85.71" height="250" />
<rect class="vin-chart__hit" data-i="1" x="85.71" y="0" width="85.71" height="250" />
<rect class="vin-chart__hit" data-i="2" x="171.43" y="0" width="85.71" height="250" />
<rect class="vin-chart__hit" data-i="3" x="257.14" y="0" width="85.71" height="250" />
<rect class="vin-chart__hit" data-i="4" x="342.86" y="0" width="85.71" height="250" />
<rect class="vin-chart__hit" data-i="5" x="428.57" y="0" width="85.71" height="250" />
<rect class="vin-chart__hit" data-i="6" x="514.29" y="0" width="85.71" height="250" />
<g class="vin-chart__series" style="--vin-series:var(--vin-chart-1)">
<path class="vin-chart__line" d="M42.86 118.75L128.57 68.75L214.29 90.63L300 21.88L385.71 34.38L471.43 131.25L557.14 153.13" />
<circle class="vin-chart__point" data-i="0" cx="42.86" cy="118.75" r="3.5" />
<circle class="vin-chart__point" data-i="1" cx="128.57" cy="68.75" r="3.5" />
<circle class="vin-chart__point" data-i="2" cx="214.29" cy="90.63" r="3.5" />
<circle class="vin-chart__point" data-i="3" cx="300" cy="21.88" r="3.5" />
<circle class="vin-chart__point" data-i="4" cx="385.71" cy="34.38" r="3.5" />
<circle class="vin-chart__point" data-i="5" cx="471.43" cy="131.25" r="3.5" />
<circle class="vin-chart__point" data-i="6" cx="557.14" cy="153.13" r="3.5" />
</g>
<g class="vin-chart__series" style="--vin-series:var(--vin-chart-2)">
<path class="vin-chart__line" d="M42.86 140.63L128.57 121.88L214.29 96.88L300 87.5L385.71 59.38L471.43 156.25L557.14 175" />
<circle class="vin-chart__point" data-i="0" cx="42.86" cy="140.63" r="3.5" />
<circle class="vin-chart__point" data-i="1" cx="128.57" cy="121.88" r="3.5" />
<circle class="vin-chart__point" data-i="2" cx="214.29" cy="96.88" r="3.5" />
<circle class="vin-chart__point" data-i="3" cx="300" cy="87.5" r="3.5" />
<circle class="vin-chart__point" data-i="4" cx="385.71" cy="59.38" r="3.5" />
<circle class="vin-chart__point" data-i="5" cx="471.43" cy="156.25" r="3.5" />
<circle class="vin-chart__point" data-i="6" cx="557.14" cy="175" r="3.5" />
</g>
<path class="vin-chart__axis" d="M0 250H600" />
</svg>
</div>
<div class="vin-chart__x" aria-hidden="true">
<span class="vin-chart__tick" style="left:7.14%">Mon</span>
<span class="vin-chart__tick" style="left:21.43%">Tue</span>
<span class="vin-chart__tick" style="left:35.71%">Wed</span>
<span class="vin-chart__tick" style="left:50%">Thu</span>
<span class="vin-chart__tick" style="left:64.29%">Fri</span>
<span class="vin-chart__tick" style="left:78.57%">Sat</span>
<span class="vin-chart__tick" style="left:92.86%">Sun</span>
</div>
</div>
<table class="vin-chart__table">
<caption>Signups per day, this week and last week</caption>
<thead>
<tr><th scope="col">Day</th><th scope="col">This week</th><th scope="col">Last week</th></tr>
</thead>
<tbody>
<tr><th scope="row">Mon</th><td>42</td><td>35</td></tr>
<tr><th scope="row">Tue</th><td>58</td><td>41</td></tr>
<tr><th scope="row">Wed</th><td>51</td><td>49</td></tr>
<tr><th scope="row">Thu</th><td>73</td><td>52</td></tr>
<tr><th scope="row">Fri</th><td>69</td><td>61</td></tr>
<tr><th scope="row">Sat</th><td>38</td><td>30</td></tr>
<tr><th scope="row">Sun</th><td>31</td><td>24</td></tr>
</tbody>
</table>
</div>| Day | This week | Last week |
|---|---|---|
| Mon | 42 | 35 |
| Tue | 58 | 41 |
| Wed | 51 | 49 |
| Thu | 73 | 52 |
| Fri | 69 | 61 |
| Sat | 38 | 30 |
| Sun | 31 | 24 |
import { Chart } from "@/components/vin/chart";
const signups = [
{ day: "Mon", now: 42, before: 35 },
{ day: "Tue", now: 58, before: 41 },
{ day: "Wed", now: 51, before: 49 },
{ day: "Thu", now: 73, before: 52 },
{ day: "Fri", now: 69, before: 61 },
{ day: "Sat", now: 38, before: 30 },
{ day: "Sun", now: 31, before: 24 },
];
export function ChartLine() {
return (
<Chart
type="line"
label="Signups per day, this week and last week"
data={signups}
index="day"
indexLabel="Day"
series={[{ key: "now", label: "This week" }, { key: "before", label: "Last week" }]}
style={{ maxWidth: 560 }}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Chart from "@/components/vin/chart.vue";
const signups = [
{ day: "Mon", now: 42, before: 35 },
{ day: "Tue", now: 58, before: 41 },
{ day: "Wed", now: 51, before: 49 },
{ day: "Thu", now: 73, before: 52 },
{ day: "Fri", now: 69, before: 61 },
{ day: "Sat", now: 38, before: 30 },
{ day: "Sun", now: 31, before: 24 },
];
</script>
<template>
<Chart
type="line"
label="Signups per day, this week and last week"
:data="signups"
index="day"
index-label="Day"
:series="[{ key: 'now', label: 'This week' }, { key: 'before', label: 'Last week' }]"
style="max-width: 560px"
/>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Chart from "$lib/components/vin/chart.svelte";
const signups = [
{ day: "Mon", now: 42, before: 35 },
{ day: "Tue", now: 58, before: 41 },
{ day: "Wed", now: 51, before: 49 },
{ day: "Thu", now: 73, before: 52 },
{ day: "Fri", now: 69, before: 61 },
{ day: "Sat", now: 38, before: 30 },
{ day: "Sun", now: 31, before: 24 },
];
</script>
<Chart
type="line"
label="Signups per day, this week and last week"
data={signups}
index="day"
indexLabel="Day"
series={[
{ key: "now", label: "This week" },
{ key: "before", label: "Last week" },
]}
style="max-width: 560px"
/>Area
One series, so no legend. Values and ticks are formatted as rupees.
| Month | Revenue |
|---|---|
| Jan | ₹12,400 |
| Feb | ₹15,100 |
| Mar | ₹14,200 |
| Apr | ₹18,900 |
| May | ₹22,300 |
| Jun | ₹21,000 |
| Jul | ₹26,400 |
| Aug | ₹29,800 |
<div class="vin-chart vin-chart--area" data-vin-chart style="--vin-chart-axis:5ch;max-width:560px">
<div class="vin-chart__body">
<div class="vin-chart__y" aria-hidden="true">
<span class="vin-chart__tick" style="top:100%">₹0</span>
<span class="vin-chart__tick" style="top:66.67%">₹10K</span>
<span class="vin-chart__tick" style="top:33.33%">₹20K</span>
<span class="vin-chart__tick" style="top:0%">₹30K</span>
</div>
<div class="vin-chart__plot">
<svg class="vin-chart__svg" viewBox="0 0 600 250" role="img" aria-label="Revenue by month, January to August (area chart)" tabindex="0">
<path class="vin-chart__grid" d="M0 166.67H600M0 83.33H600M0 0H600" />
<rect class="vin-chart__hit" data-i="0" x="0" y="0" width="75" height="250" />
<rect class="vin-chart__hit" data-i="1" x="75" y="0" width="75" height="250" />
<rect class="vin-chart__hit" data-i="2" x="150" y="0" width="75" height="250" />
<rect class="vin-chart__hit" data-i="3" x="225" y="0" width="75" height="250" />
<rect class="vin-chart__hit" data-i="4" x="300" y="0" width="75" height="250" />
<rect class="vin-chart__hit" data-i="5" x="375" y="0" width="75" height="250" />
<rect class="vin-chart__hit" data-i="6" x="450" y="0" width="75" height="250" />
<rect class="vin-chart__hit" data-i="7" x="525" y="0" width="75" height="250" />
<g class="vin-chart__series" style="--vin-series:var(--vin-chart-1)">
<path class="vin-chart__area" d="M37.5 146.67L112.5 124.17L187.5 131.67L262.5 92.5L337.5 64.17L412.5 75L487.5 30L562.5 1.67L562.5 250L37.5 250Z" />
<path class="vin-chart__line" d="M37.5 146.67L112.5 124.17L187.5 131.67L262.5 92.5L337.5 64.17L412.5 75L487.5 30L562.5 1.67" />
<circle class="vin-chart__point" data-i="0" cx="37.5" cy="146.67" r="3.5" />
<circle class="vin-chart__point" data-i="1" cx="112.5" cy="124.17" r="3.5" />
<circle class="vin-chart__point" data-i="2" cx="187.5" cy="131.67" r="3.5" />
<circle class="vin-chart__point" data-i="3" cx="262.5" cy="92.5" r="3.5" />
<circle class="vin-chart__point" data-i="4" cx="337.5" cy="64.17" r="3.5" />
<circle class="vin-chart__point" data-i="5" cx="412.5" cy="75" r="3.5" />
<circle class="vin-chart__point" data-i="6" cx="487.5" cy="30" r="3.5" />
<circle class="vin-chart__point" data-i="7" cx="562.5" cy="1.67" r="3.5" />
</g>
<path class="vin-chart__axis" d="M0 250H600" />
</svg>
</div>
<div class="vin-chart__x" aria-hidden="true">
<span class="vin-chart__tick" style="left:6.25%">Jan</span>
<span class="vin-chart__tick" style="left:18.75%">Feb</span>
<span class="vin-chart__tick" style="left:31.25%">Mar</span>
<span class="vin-chart__tick" style="left:43.75%">Apr</span>
<span class="vin-chart__tick" style="left:56.25%">May</span>
<span class="vin-chart__tick" style="left:68.75%">Jun</span>
<span class="vin-chart__tick" style="left:81.25%">Jul</span>
<span class="vin-chart__tick" style="left:93.75%">Aug</span>
</div>
</div>
<table class="vin-chart__table">
<caption>Revenue by month, January to August</caption>
<thead>
<tr><th scope="col">Month</th><th scope="col">Revenue</th></tr>
</thead>
<tbody>
<tr><th scope="row">Jan</th><td>₹12,400</td></tr>
<tr><th scope="row">Feb</th><td>₹15,100</td></tr>
<tr><th scope="row">Mar</th><td>₹14,200</td></tr>
<tr><th scope="row">Apr</th><td>₹18,900</td></tr>
<tr><th scope="row">May</th><td>₹22,300</td></tr>
<tr><th scope="row">Jun</th><td>₹21,000</td></tr>
<tr><th scope="row">Jul</th><td>₹26,400</td></tr>
<tr><th scope="row">Aug</th><td>₹29,800</td></tr>
</tbody>
</table>
</div>| Month | Revenue |
|---|---|
| Jan | ₹12,400 |
| Feb | ₹15,100 |
| Mar | ₹14,200 |
| Apr | ₹18,900 |
| May | ₹22,300 |
| Jun | ₹21,000 |
| Jul | ₹26,400 |
| Aug | ₹29,800 |
import { Chart } from "@/components/vin/chart";
const revenue = [
{ month: "Jan", revenue: 12400 },
{ month: "Feb", revenue: 15100 },
{ month: "Mar", revenue: 14200 },
{ month: "Apr", revenue: 18900 },
{ month: "May", revenue: 22300 },
{ month: "Jun", revenue: 21000 },
{ month: "Jul", revenue: 26400 },
{ month: "Aug", revenue: 29800 },
];
const inr = new Intl.NumberFormat("en-IN", { style: "currency", currency: "INR", maximumFractionDigits: 0 });
const short = new Intl.NumberFormat("en-IN", { style: "currency", currency: "INR", notation: "compact", maximumFractionDigits: 0 });
export function ChartArea() {
return (
<Chart
type="area"
label="Revenue by month, January to August"
data={revenue}
index="month"
indexLabel="Month"
series={[{ key: "revenue", label: "Revenue" }]}
format={(v) => inr.format(v)}
tickFormat={(v) => short.format(v)}
style={{ maxWidth: 560 }}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Chart from "@/components/vin/chart.vue";
const revenue = [
{ month: "Jan", revenue: 12400 },
{ month: "Feb", revenue: 15100 },
{ month: "Mar", revenue: 14200 },
{ month: "Apr", revenue: 18900 },
{ month: "May", revenue: 22300 },
{ month: "Jun", revenue: 21000 },
{ month: "Jul", revenue: 26400 },
{ month: "Aug", revenue: 29800 },
];
const inr = new Intl.NumberFormat("en-IN", { style: "currency", currency: "INR", maximumFractionDigits: 0 });
const short = new Intl.NumberFormat("en-IN", { style: "currency", currency: "INR", notation: "compact", maximumFractionDigits: 0 });
const format = (v: number) => inr.format(v);
const tickFormat = (v: number) => short.format(v);
</script>
<template>
<Chart
type="area"
label="Revenue by month, January to August"
:data="revenue"
index="month"
index-label="Month"
:series="[{ key: 'revenue', label: 'Revenue' }]"
:format="format"
:tick-format="tickFormat"
style="max-width: 560px"
/>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Chart from "$lib/components/vin/chart.svelte";
const revenue = [
{ month: "Jan", revenue: 12400 },
{ month: "Feb", revenue: 15100 },
{ month: "Mar", revenue: 14200 },
{ month: "Apr", revenue: 18900 },
{ month: "May", revenue: 22300 },
{ month: "Jun", revenue: 21000 },
{ month: "Jul", revenue: 26400 },
{ month: "Aug", revenue: 29800 },
];
const inr = new Intl.NumberFormat("en-IN", { style: "currency", currency: "INR", maximumFractionDigits: 0 });
const short = new Intl.NumberFormat("en-IN", { style: "currency", currency: "INR", notation: "compact", maximumFractionDigits: 0 });
</script>
<Chart
type="area"
label="Revenue by month, January to August"
data={revenue}
index="month"
indexLabel="Month"
series={[{ key: "revenue", label: "Revenue" }]}
format={(v) => inr.format(v)}
tickFormat={(v) => short.format(v)}
style="max-width: 560px"
/>Stacked bar
Three series stacked into one bar per month, so the height is the total. The tooltip still lists each series.
<div class="vin-chart vin-chart--bar" data-vin-chart style="--vin-chart-axis:5ch">
<div class="vin-chart__legend" aria-hidden="true">
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-1)"></span>Organic</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-2)"></span>Paid</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-3)"></span>Referral</span>
</div>
<div class="vin-chart__body">
<div class="vin-chart__y" aria-hidden="true">
<span class="vin-chart__tick" style="top:100%">0</span>
<span class="vin-chart__tick" style="top:66.67%">500</span>
<span class="vin-chart__tick" style="top:33.33%">1K</span>
<span class="vin-chart__tick" style="top:0%">1.5K</span>
</div>
<div class="vin-chart__plot">
<svg class="vin-chart__svg" viewBox="0 0 600 250" role="img" aria-label="Visits by traffic source, January to June (stacked bar chart)" tabindex="0">
<path class="vin-chart__grid" d="M0 166.67H600M0 83.33H600M0 0H600" />
<rect class="vin-chart__hit" data-i="0" x="0" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="1" x="100" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="2" x="200" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="3" x="300" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="4" x="400" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="5" x="500" y="0" width="100" height="250" />
<g class="vin-chart__series" style="--vin-series:var(--vin-chart-1)">
<rect class="vin-chart__bar" data-i="0" x="22" y="180" width="56" height="70" />
<rect class="vin-chart__bar" data-i="1" x="122" y="170" width="56" height="80" />
<rect class="vin-chart__bar" data-i="2" x="222" y="165" width="56" height="85" />
<rect class="vin-chart__bar" data-i="3" x="322" y="156.67" width="56" height="93.33" />
<rect class="vin-chart__bar" data-i="4" x="422" y="148.33" width="56" height="101.67" />
<rect class="vin-chart__bar" data-i="5" x="522" y="135" width="56" height="115" />
</g>
<g class="vin-chart__series" style="--vin-series:var(--vin-chart-2)">
<rect class="vin-chart__bar" data-i="0" x="22" y="145" width="56" height="35" />
<rect class="vin-chart__bar" data-i="1" x="122" y="126.67" width="56" height="43.33" />
<rect class="vin-chart__bar" data-i="2" x="222" y="125" width="56" height="40" />
<rect class="vin-chart__bar" data-i="3" x="322" y="106.67" width="56" height="50" />
<rect class="vin-chart__bar" data-i="4" x="422" y="95" width="56" height="53.33" />
<rect class="vin-chart__bar" data-i="5" x="522" y="83.33" width="56" height="51.67" />
</g>
<g class="vin-chart__series" style="--vin-series:var(--vin-chart-3)">
<rect class="vin-chart__bar" data-i="0" x="22" y="130" width="56" height="15" />
<rect class="vin-chart__bar" data-i="1" x="122" y="108.33" width="56" height="18.34" />
<rect class="vin-chart__bar" data-i="2" x="222" y="100" width="56" height="25" />
<rect class="vin-chart__bar" data-i="3" x="322" y="83.33" width="56" height="23.34" />
<rect class="vin-chart__bar" data-i="4" x="422" y="66.67" width="56" height="28.33" />
<rect class="vin-chart__bar" data-i="5" x="522" y="48.33" width="56" height="35" />
</g>
<path class="vin-chart__axis" d="M0 250H600" />
</svg>
</div>
<div class="vin-chart__x" aria-hidden="true">
<span class="vin-chart__tick" style="left:8.33%">Jan</span>
<span class="vin-chart__tick" style="left:25%">Feb</span>
<span class="vin-chart__tick" style="left:41.67%">Mar</span>
<span class="vin-chart__tick" style="left:58.33%">Apr</span>
<span class="vin-chart__tick" style="left:75%">May</span>
<span class="vin-chart__tick" style="left:91.67%">Jun</span>
</div>
</div>
<table class="vin-chart__table">
<caption>Visits by traffic source, January to June</caption>
<thead>
<tr>
<th scope="col">Month</th>
<th scope="col">Organic</th>
<th scope="col">Paid</th>
<th scope="col">Referral</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Jan</th>
<td>420</td>
<td>210</td>
<td>90</td>
</tr>
<tr>
<th scope="row">Feb</th>
<td>480</td>
<td>260</td>
<td>110</td>
</tr>
<tr>
<th scope="row">Mar</th>
<td>510</td>
<td>240</td>
<td>150</td>
</tr>
<tr>
<th scope="row">Apr</th>
<td>560</td>
<td>300</td>
<td>140</td>
</tr>
<tr>
<th scope="row">May</th>
<td>610</td>
<td>320</td>
<td>170</td>
</tr>
<tr>
<th scope="row">Jun</th>
<td>690</td>
<td>310</td>
<td>210</td>
</tr>
</tbody>
</table>
</div>import { Chart } from "@/components/vin/chart";
const traffic = [
{ month: "Jan", organic: 420, paid: 210, referral: 90 },
{ month: "Feb", organic: 480, paid: 260, referral: 110 },
{ month: "Mar", organic: 510, paid: 240, referral: 150 },
{ month: "Apr", organic: 560, paid: 300, referral: 140 },
{ month: "May", organic: 610, paid: 320, referral: 170 },
{ month: "Jun", organic: 690, paid: 310, referral: 210 },
];
export function ChartStacked() {
return (
<Chart
type="bar"
stacked
label="Visits by traffic source, January to June"
data={traffic}
index="month"
indexLabel="Month"
series={[{ key: "organic", label: "Organic" }, { key: "paid", label: "Paid" }, { key: "referral", label: "Referral" }]}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Chart from "@/components/vin/chart.vue";
const traffic = [
{ month: "Jan", organic: 420, paid: 210, referral: 90 },
{ month: "Feb", organic: 480, paid: 260, referral: 110 },
{ month: "Mar", organic: 510, paid: 240, referral: 150 },
{ month: "Apr", organic: 560, paid: 300, referral: 140 },
{ month: "May", organic: 610, paid: 320, referral: 170 },
{ month: "Jun", organic: 690, paid: 310, referral: 210 },
];
</script>
<template>
<Chart
type="bar"
stacked
label="Visits by traffic source, January to June"
:data="traffic"
index="month"
index-label="Month"
:series="[{ key: 'organic', label: 'Organic' }, { key: 'paid', label: 'Paid' }, { key: 'referral', label: 'Referral' }]"
/>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Chart from "$lib/components/vin/chart.svelte";
const traffic = [
{ month: "Jan", organic: 420, paid: 210, referral: 90 },
{ month: "Feb", organic: 480, paid: 260, referral: 110 },
{ month: "Mar", organic: 510, paid: 240, referral: 150 },
{ month: "Apr", organic: 560, paid: 300, referral: 140 },
{ month: "May", organic: 610, paid: 320, referral: 170 },
{ month: "Jun", organic: 690, paid: 310, referral: 210 },
];
</script>
<Chart
type="bar"
stacked
label="Visits by traffic source, January to June"
data={traffic}
index="month"
indexLabel="Month"
series={[{ key: "organic", label: "Organic" }, { key: "paid", label: "Paid" }, { key: "referral", label: "Referral" }]}
/>Stacked area, smooth
Desktop and mobile stacked, drawn with a smooth curve.
| Month | Desktop | Mobile |
|---|---|---|
| Jan | 186 | 80 |
| Feb | 305 | 200 |
| Mar | 237 | 120 |
| Apr | 73 | 190 |
| May | 209 | 130 |
| Jun | 214 | 140 |
<div class="vin-chart vin-chart--area" data-vin-chart style="--vin-chart-axis:4ch">
<div class="vin-chart__legend" aria-hidden="true">
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-1)"></span>Desktop</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-2)"></span>Mobile</span>
</div>
<div class="vin-chart__body">
<div class="vin-chart__y" aria-hidden="true">
<span class="vin-chart__tick" style="top:100%">0</span>
<span class="vin-chart__tick" style="top:66.67%">200</span>
<span class="vin-chart__tick" style="top:33.33%">400</span>
<span class="vin-chart__tick" style="top:0%">600</span>
</div>
<div class="vin-chart__plot">
<svg class="vin-chart__svg" viewBox="0 0 600 250" role="img" aria-label="Visitors by device, January to June (stacked area chart)" tabindex="0">
<path class="vin-chart__grid" d="M0 166.67H600M0 83.33H600M0 0H600" />
<rect class="vin-chart__hit" data-i="0" x="0" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="1" x="100" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="2" x="200" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="3" x="300" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="4" x="400" y="0" width="100" height="250" />
<rect class="vin-chart__hit" data-i="5" x="500" y="0" width="100" height="250" />
<g class="vin-chart__series" style="--vin-series:var(--vin-chart-1)">
<path class="vin-chart__area" d="M50 172.5C83.33 155.97 116.67 122.92 150 122.92C183.33 122.92 216.67 137.9 250 151.25C283.33 164.6 316.67 219.58 350 219.58C383.33 219.58 416.67 164.26 450 162.92C483.33 161.58 516.67 161.53 550 160.83L550 250C516.67 250 483.33 250 450 250C416.67 250 383.33 250 350 250C316.67 250 283.33 250 250 250C216.67 250 183.33 250 150 250C116.67 250 83.33 250 50 250Z" />
<path class="vin-chart__line" d="M50 172.5C83.33 155.97 116.67 122.92 150 122.92C183.33 122.92 216.67 137.9 250 151.25C283.33 164.6 316.67 219.58 350 219.58C383.33 219.58 416.67 164.26 450 162.92C483.33 161.58 516.67 161.53 550 160.83" />
<circle class="vin-chart__point" data-i="0" cx="50" cy="172.5" r="3.5" />
<circle class="vin-chart__point" data-i="1" cx="150" cy="122.92" r="3.5" />
<circle class="vin-chart__point" data-i="2" cx="250" cy="151.25" r="3.5" />
<circle class="vin-chart__point" data-i="3" cx="350" cy="219.58" r="3.5" />
<circle class="vin-chart__point" data-i="4" cx="450" cy="162.92" r="3.5" />
<circle class="vin-chart__point" data-i="5" cx="550" cy="160.83" r="3.5" />
</g>
<g class="vin-chart__series" style="--vin-series:var(--vin-chart-2)">
<path class="vin-chart__area" d="M50 139.17C83.33 105.97 116.67 39.58 150 39.58C183.33 39.58 216.67 85.28 250 101.25C283.33 117.22 316.67 140.42 350 140.42C383.33 140.42 416.67 112.23 450 108.75C483.33 105.27 516.67 104.58 550 102.5L550 160.83C516.67 161.53 483.33 161.58 450 162.92C416.67 164.26 383.33 219.58 350 219.58C316.67 219.58 283.33 164.6 250 151.25C216.67 137.9 183.33 122.92 150 122.92C116.67 122.92 83.33 155.97 50 172.5Z" />
<path class="vin-chart__line" d="M50 139.17C83.33 105.97 116.67 39.58 150 39.58C183.33 39.58 216.67 85.28 250 101.25C283.33 117.22 316.67 140.42 350 140.42C383.33 140.42 416.67 112.23 450 108.75C483.33 105.27 516.67 104.58 550 102.5" />
<circle class="vin-chart__point" data-i="0" cx="50" cy="139.17" r="3.5" />
<circle class="vin-chart__point" data-i="1" cx="150" cy="39.58" r="3.5" />
<circle class="vin-chart__point" data-i="2" cx="250" cy="101.25" r="3.5" />
<circle class="vin-chart__point" data-i="3" cx="350" cy="140.42" r="3.5" />
<circle class="vin-chart__point" data-i="4" cx="450" cy="108.75" r="3.5" />
<circle class="vin-chart__point" data-i="5" cx="550" cy="102.5" r="3.5" />
</g>
<path class="vin-chart__axis" d="M0 250H600" />
</svg>
</div>
<div class="vin-chart__x" aria-hidden="true">
<span class="vin-chart__tick" style="left:8.33%">Jan</span>
<span class="vin-chart__tick" style="left:25%">Feb</span>
<span class="vin-chart__tick" style="left:41.67%">Mar</span>
<span class="vin-chart__tick" style="left:58.33%">Apr</span>
<span class="vin-chart__tick" style="left:75%">May</span>
<span class="vin-chart__tick" style="left:91.67%">Jun</span>
</div>
</div>
<table class="vin-chart__table">
<caption>Visitors by device, January to June</caption>
<thead>
<tr>
<th scope="col">Month</th>
<th scope="col">Desktop</th>
<th scope="col">Mobile</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Jan</th>
<td>186</td>
<td>80</td>
</tr>
<tr>
<th scope="row">Feb</th>
<td>305</td>
<td>200</td>
</tr>
<tr>
<th scope="row">Mar</th>
<td>237</td>
<td>120</td>
</tr>
<tr>
<th scope="row">Apr</th>
<td>73</td>
<td>190</td>
</tr>
<tr>
<th scope="row">May</th>
<td>209</td>
<td>130</td>
</tr>
<tr>
<th scope="row">Jun</th>
<td>214</td>
<td>140</td>
</tr>
</tbody>
</table>
</div>| Month | Desktop | Mobile |
|---|---|---|
| Jan | 186 | 80 |
| Feb | 305 | 200 |
| Mar | 237 | 120 |
| Apr | 73 | 190 |
| May | 209 | 130 |
| Jun | 214 | 140 |
import { Chart } from "@/components/vin/chart";
const visitors = [
{ month: "Jan", desktop: 186, mobile: 80 },
{ month: "Feb", desktop: 305, mobile: 200 },
{ month: "Mar", desktop: 237, mobile: 120 },
{ month: "Apr", desktop: 73, mobile: 190 },
{ month: "May", desktop: 209, mobile: 130 },
{ month: "Jun", desktop: 214, mobile: 140 },
];
export function ChartSmooth() {
return (
<Chart
type="area"
stacked
curve="smooth"
label="Visitors by device, January to June"
data={visitors}
index="month"
indexLabel="Month"
series={[{ key: "desktop", label: "Desktop" }, { key: "mobile", label: "Mobile" }]}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Chart from "@/components/vin/chart.vue";
const visitors = [
{ month: "Jan", desktop: 186, mobile: 80 },
{ month: "Feb", desktop: 305, mobile: 200 },
{ month: "Mar", desktop: 237, mobile: 120 },
{ month: "Apr", desktop: 73, mobile: 190 },
{ month: "May", desktop: 209, mobile: 130 },
{ month: "Jun", desktop: 214, mobile: 140 },
];
</script>
<template>
<Chart
type="area"
stacked
curve="smooth"
label="Visitors by device, January to June"
:data="visitors"
index="month"
index-label="Month"
:series="[{ key: 'desktop', label: 'Desktop' }, { key: 'mobile', label: 'Mobile' }]"
/>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Chart from "$lib/components/vin/chart.svelte";
const visitors = [
{ month: "Jan", desktop: 186, mobile: 80 },
{ month: "Feb", desktop: 305, mobile: 200 },
{ month: "Mar", desktop: 237, mobile: 120 },
{ month: "Apr", desktop: 73, mobile: 190 },
{ month: "May", desktop: 209, mobile: 130 },
{ month: "Jun", desktop: 214, mobile: 140 },
];
</script>
<Chart
type="area"
stacked
curve="smooth"
label="Visitors by device, January to June"
data={visitors}
index="month"
indexLabel="Month"
series={[{ key: "desktop", label: "Desktop" }, { key: "mobile", label: "Mobile" }]}
/>Pie
One slice per row. Hover a slice, or focus the chart and use the arrow keys, to see its value.
| Browser | Visitors |
|---|---|
| Chrome | 275 |
| Safari | 200 |
| Firefox | 187 |
| Edge | 173 |
| Other | 90 |
<div class="vin-chart vin-chart--pie" data-vin-chart>
<div class="vin-chart__legend" aria-hidden="true">
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-1)"></span>Chrome</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-2)"></span>Safari</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-3)"></span>Firefox</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-4)"></span>Edge</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-5)"></span>Other</span>
</div>
<div class="vin-chart__body">
<div class="vin-chart__plot">
<svg class="vin-chart__svg" viewBox="0 0 200 200" role="img" aria-label="Visitors by browser (pie chart)" tabindex="0">
<path class="vin-chart__slice" data-i="0" d="M100 100L100 4A96 96 0 0 1 191.79 128.11Z" style="--vin-series:var(--vin-chart-1)" />
<path class="vin-chart__slice" data-i="1" d="M100 100L191.79 128.11A96 96 0 0 1 91.86 195.65Z" style="--vin-series:var(--vin-chart-2)" />
<path class="vin-chart__slice" data-i="2" d="M100 100L91.86 195.65A96 96 0 0 1 6.22 120.54Z" style="--vin-series:var(--vin-chart-3)" />
<path class="vin-chart__slice" data-i="3" d="M100 100L6.22 120.54A96 96 0 0 1 44.9 21.39Z" style="--vin-series:var(--vin-chart-4)" />
<path class="vin-chart__slice" data-i="4" d="M100 100L44.9 21.39A96 96 0 0 1 100 4Z" style="--vin-series:var(--vin-chart-5)" />
</svg>
</div>
</div>
<table class="vin-chart__table">
<caption>Visitors by browser</caption>
<thead>
<tr>
<th scope="col">Browser</th>
<th scope="col">Visitors</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Chrome</th>
<td>275</td>
</tr>
<tr>
<th scope="row">Safari</th>
<td>200</td>
</tr>
<tr>
<th scope="row">Firefox</th>
<td>187</td>
</tr>
<tr>
<th scope="row">Edge</th>
<td>173</td>
</tr>
<tr>
<th scope="row">Other</th>
<td>90</td>
</tr>
</tbody>
</table>
</div>| Browser | Visitors |
|---|---|
| Chrome | 275 |
| Safari | 200 |
| Firefox | 187 |
| Edge | 173 |
| Other | 90 |
import { Chart } from "@/components/vin/chart";
const browsers = [
{ browser: "Chrome", visitors: 275 },
{ browser: "Safari", visitors: 200 },
{ browser: "Firefox", visitors: 187 },
{ browser: "Edge", visitors: 173 },
{ browser: "Other", visitors: 90 },
];
export function ChartPie() {
return (
<Chart
type="pie"
label="Visitors by browser"
data={browsers}
index="browser"
indexLabel="Browser"
series={[{ key: "visitors", label: "Visitors" }]}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Chart from "@/components/vin/chart.vue";
const browsers = [
{ browser: "Chrome", visitors: 275 },
{ browser: "Safari", visitors: 200 },
{ browser: "Firefox", visitors: 187 },
{ browser: "Edge", visitors: 173 },
{ browser: "Other", visitors: 90 },
];
</script>
<template>
<Chart
type="pie"
label="Visitors by browser"
:data="browsers"
index="browser"
index-label="Browser"
:series="[{ key: 'visitors', label: 'Visitors' }]"
/>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Chart from "$lib/components/vin/chart.svelte";
const browsers = [
{ browser: "Chrome", visitors: 275 },
{ browser: "Safari", visitors: 200 },
{ browser: "Firefox", visitors: 187 },
{ browser: "Edge", visitors: 173 },
{ browser: "Other", visitors: 90 },
];
</script>
<Chart
type="pie"
label="Visitors by browser"
data={browsers}
index="browser"
indexLabel="Browser"
series={[{ key: "visitors", label: "Visitors" }]}
/>Donut
The same data as a donut, with the total and a caption in the middle (centerLabel).
| Browser | Visitors |
|---|---|
| Chrome | 275 |
| Safari | 200 |
| Firefox | 187 |
| Edge | 173 |
| Other | 90 |
<div class="vin-chart vin-chart--donut" data-vin-chart>
<div class="vin-chart__legend" aria-hidden="true">
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-1)"></span>Chrome</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-2)"></span>Safari</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-3)"></span>Firefox</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-4)"></span>Edge</span>
<span class="vin-chart__key"><span class="vin-chart__swatch" style="--vin-series:var(--vin-chart-5)"></span>Other</span>
</div>
<div class="vin-chart__body">
<div class="vin-chart__plot">
<svg class="vin-chart__svg" viewBox="0 0 200 200" role="img" aria-label="Visitors by browser (donut chart)" tabindex="0">
<path class="vin-chart__slice" data-i="0" d="M101.15 4.01A96 96 0 0 1 192.12 127.01L157.58 116.88A60 60 0 0 0 100.72 40Z" style="--vin-series:var(--vin-chart-1)" />
<path class="vin-chart__slice" data-i="1" d="M191.45 129.21A96 96 0 0 1 93.01 195.74L95.63 159.84A60 60 0 0 0 157.16 118.26Z" style="--vin-series:var(--vin-chart-2)" />
<path class="vin-chart__slice" data-i="2" d="M90.71 195.55A96 96 0 0 1 6.48 121.67L41.55 113.54A60 60 0 0 0 94.19 159.72Z" style="--vin-series:var(--vin-chart-3)" />
<path class="vin-chart__slice" data-i="3" d="M5.98 119.42A96 96 0 0 1 43.96 22.05L64.98 51.28A60 60 0 0 0 41.24 112.14Z" style="--vin-series:var(--vin-chart-4)" />
<path class="vin-chart__slice" data-i="4" d="M45.85 20.73A96 96 0 0 1 98.85 4.01L99.28 40A60 60 0 0 0 66.15 50.46Z" style="--vin-series:var(--vin-chart-5)" />
</svg>
<div class="vin-chart__center" aria-hidden="true">
<span class="vin-chart__center-value">925</span>
<span class="vin-chart__center-label">Visitors</span>
</div>
</div>
</div>
<table class="vin-chart__table">
<caption>Visitors by browser</caption>
<thead>
<tr>
<th scope="col">Browser</th>
<th scope="col">Visitors</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Chrome</th>
<td>275</td>
</tr>
<tr>
<th scope="row">Safari</th>
<td>200</td>
</tr>
<tr>
<th scope="row">Firefox</th>
<td>187</td>
</tr>
<tr>
<th scope="row">Edge</th>
<td>173</td>
</tr>
<tr>
<th scope="row">Other</th>
<td>90</td>
</tr>
</tbody>
</table>
</div>| Browser | Visitors |
|---|---|
| Chrome | 275 |
| Safari | 200 |
| Firefox | 187 |
| Edge | 173 |
| Other | 90 |
import { Chart } from "@/components/vin/chart";
const browsers = [
{ browser: "Chrome", visitors: 275 },
{ browser: "Safari", visitors: 200 },
{ browser: "Firefox", visitors: 187 },
{ browser: "Edge", visitors: 173 },
{ browser: "Other", visitors: 90 },
];
export function ChartDonut() {
return (
<Chart
type="donut"
centerLabel="Visitors"
label="Visitors by browser"
data={browsers}
index="browser"
indexLabel="Browser"
series={[{ key: "visitors", label: "Visitors" }]}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Chart from "@/components/vin/chart.vue";
const browsers = [
{ browser: "Chrome", visitors: 275 },
{ browser: "Safari", visitors: 200 },
{ browser: "Firefox", visitors: 187 },
{ browser: "Edge", visitors: 173 },
{ browser: "Other", visitors: 90 },
];
</script>
<template>
<Chart
type="donut"
center-label="Visitors"
label="Visitors by browser"
:data="browsers"
index="browser"
index-label="Browser"
:series="[{ key: 'visitors', label: 'Visitors' }]"
/>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Chart from "$lib/components/vin/chart.svelte";
const browsers = [
{ browser: "Chrome", visitors: 275 },
{ browser: "Safari", visitors: 200 },
{ browser: "Firefox", visitors: 187 },
{ browser: "Edge", visitors: 173 },
{ browser: "Other", visitors: 90 },
];
</script>
<Chart
type="donut"
centerLabel="Visitors"
label="Visitors by browser"
data={browsers}
index="browser"
indexLabel="Browser"
series={[{ key: "visitors", label: "Visitors" }]}
/>Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add chartimport { Chart, niceTicks } from "@/components/vin/chart";import Chart, { niceTicks } from "@/components/vin/chart.vue";import Chart, { niceTicks } from "$lib/components/vin/chart.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.
API
From spec/chart.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
type | barlineareapiedonut | bar | vin-chart--{type} |
labelWhat the chart shows. Names the picture and captions the data table. Required. | string | — | aria-label on svg.vin-chart__svg[role=img] and the table's caption |
dataOne row per category, in order. | Record<string, string | number>[] | — | — |
indexThe field that names each category (the x axis). | string | — | span.vin-chart__tick in .vin-chart__x |
seriesThe fields to draw. Pie and donut draw the first one, one slice per row. Colours default to the theme's --vin-chart-1 to --vin-chart-5. | { key: string; label?: string; color?: string }[] | — | g.vin-chart__series style="--vin-series: var(--vin-chart-1)" |
stackedBar and area: stack the series, so the top is the total. | boolean | false | one bar per category; areas sit on the series below |
curveLine and area: smooth draws a monotone curve that never overshoots the data. | linearsmooth | linear | C commands in path.vin-chart__line |
centerLabelDonut: caption under the total in the middle. Without it the middle stays empty. | string | — | div.vin-chart__center > span.vin-chart__center-value + span.vin-chart__center-label |
formatFormats values in the tooltip and table. Default: 12,400. | (value: number) => string | — | — |
tickFormatFormats the y-axis ticks. Default: compact (12K). | (value: number) => string | — | — |
indexLabelHeading of the first table column, e.g. "Month". | string | — | — |
aspectRatioWidth ÷ height of the plot. The chart scales with its container; labels stay full size. | number | 2.4 | the svg viewBox, e.g. "0 0 600 250" |
legendShow the legend. Default: when there's more than one series, and always for pie and donut (one key per slice). | boolean | — | .vin-chart__legend > .vin-chart__key > .vin-chart__swatch |
theme colours--vin-chart-1 is the accent; 2 to 5 turn its hue around the colour wheel at a readable lightness, so they suit any accent. Override any of them on .vin-chart. | CSS | — | --vin-chart-1 … --vin-chart-5 |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<Chart> | .vin-chart.vin-chart--bar.vin-chart--line.vin-chart--area.vin-chart--pie.vin-chart--donut.vin-chart__legend.vin-chart__key.vin-chart__swatch.vin-chart__body.vin-chart__y.vin-chart__x.vin-chart__tick.vin-chart__plot.vin-chart__svg.vin-chart__grid.vin-chart__axis.vin-chart__hit.vin-chart__series.vin-chart__bar.vin-chart__line.vin-chart__area.vin-chart__point.vin-chart__slice.vin-chart__center.vin-chart__center-value.vin-chart__center-label.vin-chart__tooltip.vin-chart__tooltip-title.vin-chart__tooltip-row.vin-chart__value.vin-chart__table |
Accessibility
- The SVG has role="img" and a label that says what it shows; the same numbers are in a visually hidden table (caption, column and row headers) right after it.
- The legend and axis labels are hidden from screen readers because the table already says it all.
- The chart can be focused: Left and Right (or Up and Down), Home and End move between categories and show a tooltip; Escape hides it. The tooltip also follows the pointer.
- Series colours start from your accent and keep a mid lightness, so lines and bars stand out on light and dark backgrounds. Colour is never the only cue: the tooltip and table name every series.
- Lines keep a 2px stroke at any size, and labels stay full size on small screens because they are HTML, not SVG text.
- Pie and donut slices are labelled the same way: the table has one row per slice, and the arrow keys move between slices.
Customize
Saved in this browser. Style and accent are in the header.