Size & resizing
Charts are drawn in SVG at their real size in pixels, never stretched: a
resize redraws them, so their lines stay crisp, their labels readable,
and their axes fitted to the room they have. Their width always follows
their parent; their height is set by --chart-height, or by their parent
with fill.
Width
A chart is a block taking its parent's width, and it can shrink inside a
grid or a flex row (min-width: 0). It watches its own size, and
redraws on every change, whatever caused it: a window resized, a sidebar
collapsed, a card moved to another column. On each redraw:
- the category labels thin out to fit, the last one always shown;
- the value axis takes the room its widest label needs;
- bars take the width their category leaves them, between a least and a greatest width;
- the tooltip opens on whichever side has the most room;
- the legend wraps onto as many rows as it needs.
Drag the corner of the box below to see it.
Height
The height is set by --chart-height, 220px by default, axis labels
included; the legend, when shown, adds its row under it. Like any custom
property, it can be set on the chart or any ancestor, and change with a
breakpoint or a class: the chart redraws at the new height.
.dashboard {
--chart-height: 180px;
}
@media (width >= 1024px) {
.dashboard {
--chart-height: 260px;
}
}
On a pie or a doughnut, the diameter follows the height, the pie centered in the width.
Filling its parent
fill takes the height from the parent instead: the chart takes 100%
of its parent's height, the legend included, the plot stretching to
what's left once the legend is laid out. It redraws on every change of
height, as it does for the width, and --chart-height is ignored.
<div class="card" style="height: 320px">
<eun-line-chart
label="Sessions per month, in thousands"
fill
></eun-line-chart>
</div>
The parent needs a height of its own for 100% to mean something: an
explicit height, a grid row, or a stretched flex item. Inside a card
whose content stacks in a column (a title, then the chart), give the
chart flex: 1 to take the room under the title:
Sessions
Revenue per channel
.cards {
display: grid;
grid-template-columns: 2fr 1fr;
grid-auto-rows: 280px;
}
.card {
display: flex;
flex-direction: column;
}
.card > eun-line-chart,
.card > eun-doughnut-chart {
flex: 1;
}
<div class="cards">
<div class="card">
<h3>Sessions</h3>
<eun-line-chart fill></eun-line-chart>
</div>
<div class="card">
<h3>Revenue per channel</h3>
<eun-doughnut-chart fill></eun-doughnut-chart>
</div>
</div>
In a parent too small, the plot keeps a least height,
--chart-min-height (80px by default), rather than vanishing. While
loading, the placeholder takes the same room, round and as large as
the height allows on a pie or a doughnut.
Small charts
With its axes and its grid hidden, a chart keeps its whole room for the marks: a sparkline for a card or a table cell, its values still in the tooltip and the data table.
<eun-line-chart
label="Sessions per month"
hide-grid
hide-value-axis
hide-category-axis
style="--chart-height: 48px"
></eun-line-chart>
In a list, a table cell or a card, add non-interactive: the chart
becomes a plain picture, with no focus stop, no hover and no tooltip, so
tabbing through the page doesn't stop on every chart and a click reaches
the row or the card itself. It keeps its label and its data table for
screen readers. Here, sessions per channel over 2026, in a
- Website
-
72K - App
-
49K - Store
-
9K
<eun-description-list divided>
<dl>
<div>
<dt>Website</dt>
<dd>
<span class="spark-row">
<eun-line-chart
label="Website sessions per month"
non-interactive
hide-grid
hide-value-axis
hide-category-axis
style="--chart-height: 32px"
></eun-line-chart>
<strong>72K</strong>
</span>
</dd>
</div>
</dl>
</eun-description-list>
Before it upgrades
Until its script has loaded, a chart is an unknown element with no size,
so the page would shift once it draws. chart-ssr.css reserves its room
up front: --chart-height, plus the legend's row once
legend="visible", or 100% of its parent's height with fill. Import
it with the page's other styles:
@import "@eunomia/charts/chart-ssr.css";
See also