Chart
BetaData displayOpen in the workshop
Line, area, bar and donut charts styled from the chart tokens; any library, same look.
.xg-chart > ul.xg-legend + svg (classes: grid, axis, line, area, bar, dot, series-1…6, label)Example and markup
Live, from xg-ui.css and xg-ui.js. Switch the brand and mode on the example itself, or for the whole site in the header.
- Revenue, $K
- Spend, $K
Markup
<div class="xg-card">
<figure class="xg-chart" style="margin:0">
<ul class="xg-legend">
<li>
<i class="s1 is-line">
</i>Revenue, $K</li>
<li>
<i class="s2 is-line">
</i>Spend, $K</li>
</ul>
<svg viewBox="0 0 600 220" role="img" aria-labelledby="chart-cmp-t" data-xg-chart>
<title id="chart-cmp-t">Revenue rose from $42K to $78K over November; spend rose from $30K to $48K.</title>
<g class="grid">
<line x1="40" x2="592" y1="196" y2="196"/>
<line x1="40" x2="592" y1="149" y2="149"/>
<line x1="40" x2="592" y1="102" y2="102"/>
<line x1="40" x2="592" y1="55" y2="55"/>
<line x1="40" x2="592" y1="8" y2="8"/>
</g>
<g class="axis">
<text x="32" y="200" text-anchor="end">0</text>
<text x="32" y="153" text-anchor="end">25</text>
<text x="32" y="106" text-anchor="end">50</text>
<text x="32" y="59" text-anchor="end">75</text>
<text x="32" y="12" text-anchor="end">100</text>
<text x="40" y="214" text-anchor="middle">Nov 1</text>
<text x="190.54545454545453" y="214" text-anchor="middle">Nov 10</text>
<text x="341.09090909090907" y="214" text-anchor="middle">Nov 19</text>
<text x="491.6363636363637" y="214" text-anchor="middle">Nov 28</text>
<text x="592" y="214" text-anchor="middle">Nov 30</text>
</g>
<path class="area" d="M40.0 117.0 L90.2 105.8 L140.4 111.4 L190.5 96.4 L240.7 87.0 L290.9 92.6 L341.1 77.6 L391.3 81.3 L441.5 68.2 L491.6 60.6 L541.8 64.4 L592.0 49.4 L592 196 L40 196 Z"/>
<path class="line series-2" d="M40.0 139.6 L90.2 137.7 L140.4 130.2 L190.5 132.1 L240.7 124.6 L290.9 118.9 L341.1 120.8 L391.3 113.3 L441.5 115.2 L491.6 107.6 L541.8 103.9 L592.0 105.8"/>
<path class="line series-1" d="M40.0 117.0 L90.2 105.8 L140.4 111.4 L190.5 96.4 L240.7 87.0 L290.9 92.6 L341.1 77.6 L391.3 81.3 L441.5 68.2 L491.6 60.6 L541.8 64.4 L592.0 49.4"/>
<circle class="dot series-1" cx="40" cy="117.04000000000002" r="3.5" data-tip="<strong>Day 1</strong>
<br>Revenue $42K · Spend $30K"/>
<circle class="dot series-1" cx="90.18181818181819" cy="105.76" r="3.5" data-tip="<strong>Day 4</strong>
<br>Revenue $48K · Spend $31K"/>
<circle class="dot series-1" cx="140.36363636363637" cy="111.4" r="3.5" data-tip="<strong>Day 7</strong>
<br>Revenue $45K · Spend $35K"/>
<circle class="dot series-1" cx="190.54545454545453" cy="96.36" r="3.5" data-tip="<strong>Day 10</strong>
<br>Revenue $53K · Spend $34K"/>
<circle class="dot series-1" cx="240.72727272727272" cy="86.96000000000001" r="3.5" data-tip="<strong>Day 13</strong>
<br>Revenue $58K · Spend $38K"/>
<circle class="dot series-1" cx="290.9090909090909" cy="92.6" r="3.5" data-tip="<strong>Day 16</strong>
<br>Revenue $55K · Spend $41K"/>
<circle class="dot series-1" cx="341.09090909090907" cy="77.56" r="3.5" data-tip="<strong>Day 19</strong>
<br>Revenue $63K · Spend $40K"/>
<circle class="dot series-1" cx="391.27272727272725" cy="81.32000000000001" r="3.5" data-tip="<strong>Day 22</strong>
<br>Revenue $61K · Spend $44K"/>
<circle class="dot series-1" cx="441.45454545454544" cy="68.16" r="3.5" data-tip="<strong>Day 25</strong>
<br>Revenue $68K · Spend $43K"/>
<circle class="dot series-1" cx="491.6363636363637" cy="60.64000000000001" r="3.5" data-tip="<strong>Day 28</strong>
<br>Revenue $72K · Spend $47K"/>
<circle class="dot series-1" cx="541.8181818181818" cy="64.4" r="3.5" data-tip="<strong>Day 31</strong>
<br>Revenue $70K · Spend $49K"/>
<circle class="dot series-1" cx="592" cy="49.35999999999999" r="3.5" data-tip="<strong>Day 34</strong>
<br>Revenue $78K · Spend $48K"/>
</svg>
</figure>
</div>When to use it
Use it for
trends over time (line/area), comparisons (bar), a two-part share (donut).
Not for
pies with more than two slices; 3D; dual axes.
Rules
- Series 1 is always the brand color and the metric the chart is about.
- Gridlines horizontal only, faint; axis labels in chart-axis (4.5:1).
- See Data visualization for the full rules.
Accessibility
- Every chart has a text alternative that states the finding (<title> or a caption), and a table view nearby for exact values.
- Marks with tooltips are focusable.
Every color pair this component uses is measured for both brands in light and dark on the Accessibility page.
Related
Also in Data display: Data table, Pagination, KPI card, Status badge, Tag, Avatar, Progress, Tooltip, Empty state, Skeleton, Spinner. Used in the patterns Dashboard.
Status Beta: usable; class names may still change in a minor release, with a note (see Releasing).