Compact charts and sparklines
Sparklines for Blazor: Compact="true" turns any chart into one, with no axes, grid, legend or title; the series fill the box and the
y range fits the data. Give it a small Height and put it in a table, a card or a sentence.
Sparkline
The y range fits the data tightly, so small changes show (bars keep zero). Highlight marks the last, first, lowest or
highest value with a dot; it works on normal charts too. The tooltip still works, and screen readers get a short summary such as
"Web: 28 to 252 sessions, last 193, falling" instead of a tab stop.
Code
<RioChart Items="web" Compact="true" Height="40">
<LineSeries Name="Web" XValue="r => r.Time" YValue="r => r.Value" Format="#,0 'sessions'"
Highlight="PointHighlight.Last | PointHighlight.Min | PointHighlight.Max" />
</RioChart>In a table
Every interactive chart loads the JS module, measures its container and sends its points to the browser. With dozens of charts on a
page, Interactive="false" draws plain SVG instead: no JS, no tooltip, no round trips. Give it a Width so it
is drawn at its real size (without one it is laid out 160 px wide and scaled to fit). Here the water bottle keeps selling more, and
the tent shows a gap while it was sold out.
| Product | Sold per hour, 48 h | Last hour |
|---|---|---|
| Trail shoe · Ridge 2 | 20 | |
| Rain jacket · Storm | 13 | |
| Headlamp · Beam 400 | 6 | |
| Water bottle · 1 l | 19 | |
| Tent · Dome 2p | 5 |
Code
@foreach (var product in products)
{
<tr>
<td>@product.Name</td>
<td>
<RioChart Items="product.Readings" Compact="true" Interactive="false" Width="140" Height="28" Title="@product.Name">
<LineSeries Name="Sold" XValue="r => r.Time" YValue="r => r.Value" Format="0 'per hour'" Highlight="PointHighlight.Last" />
</RioChart>
</td>
<td>@product.LastHour</td>
</tr>
}Areas and bars
Area and bar series work the same way. Areas fill down to the bottom of the box; bars start at zero, so their lengths compare.
Code
<RioChart Items="revenue" Compact="true" Height="48">
<AreaSeries Name="Revenue" XValue="r => r.Time" YValue="r => r.Value" Format="#,0 €" Curve="CurveType.Monotone" />
</RioChart>
<RioChart Items="orders" Compact="true" Height="48">
<BarSeries Name="Orders" XValue="r => r.Time" YValue="r => r.Value" Format="#,0 'orders'" />
</RioChart>Target range
Annotations still draw, without their text: a ReferenceBand shows the target range at a glance. Bands do not widen the
y range, so the line keeps its detail, and a gap (here, while tracking was down) stays a gap.
Code
<RioChart Items="conversion" Compact="true" Height="40">
<LineSeries Name="Conversion" XValue="r => r.Time" YValue="r => r.Value" Format="0.00 '%'" Highlight="PointHighlight.Last" />
<ReferenceBand From="2" To="3" />
</RioChart>Pies, donuts and radial bars
Round charts work too. Compact, they drop their labels, legend and the donut's center total and fill the box, so give them a
square size and put the number next to them. A single radial bar with EndAngle="360" is a progress ring. Hover a
slice or bar for its name and value.
Code
<RioChart Items="categories" Compact="true" Width="48" Height="48" Title="Revenue per category">
<PieSeries Name="Revenue" XValue="s => s.Name" YValue="s => s.Value" Format="0 k€" InnerRadius="0.55" />
</RioChart>
@* A progress ring: one radial bar all the way round *@
<RioChart Items="revenueGoal" Compact="true" Width="48" Height="48" Title="Revenue goal">
<RadialBarSeries XValue="s => s.Name" YValue="s => s.Value" Max="100" EndAngle="360" InnerRadius="0.6" Format="0'%'" />
</RioChart>More chart types
Every chart type has a compact form: candlesticks, heatmaps, box plots, horizontal bars, treemaps and radar charts lose their axes, labels and legend the same way, and keep their tooltip.
Code
<RioChart Items="prices" Compact="true" Height="48">
<CandlestickSeries Name="Price" XValue="p => p.Date" OpenValue="p => p.First" HighValue="p => p.Highest"
LowValue="p => p.Lowest" CloseValue="p => p.Last" Format="0.0 €" DirectionColors="true" />
</RioChart>
<RioChart TItem="HourCount" Compact="true" Height="48">
@foreach (var (day, hours) in week)
{
<HeatmapSeries Items="hours" Name="@day" XValue="h => h.Hour" YValue="h => h.Sessions" Format="#,0" />
}
</RioChart>
<RioChart Items="categories" Compact="true" Horizontal="true" Height="48">
<BarSeries Name="Revenue" XValue="s => s.Name" YValue="s => s.Value" Format="0 k€" />
</RioChart>
<RioChart Items="folders" Compact="true" Height="48">
<TreemapSeries Name="Disk usage" XValue="f => f.Name" ParentValue="f => f.Parent" YValue="f => f.Gigabytes" Format="0 GB" />
</RioChart>Auto-compact
Normal charts make room for the plot as they get small: first the axis titles go, then the legend (the tooltip still names the
series), the title and the axis labels. A right legend moves to the top on narrow charts. Below 120 × 60 px the chart is drawn as a
compact chart. It is on by default; AutoCompact="false" keeps everything at any size. Pick a size:
Code
<RioChart Items="web" Height="130" Title="Store traffic"
XAxis="@(new AxisOptions { Title = "Time" })" YAxis="@(new AxisOptions { Title = "Sessions per 15 min" })">
<LineSeries Name="Web" XValue="r => r.Time" YValue="r => r.Value" Format="#,0" />
<LineSeries Items="app" Name="App" XValue="r => r.Time" YValue="r => r.Value" Format="#,0" />
</RioChart>Options
| Option | Default | Meaning |
|---|---|---|
Compact | false | No axes, grid, legend or title; a tight y range. Also "compact": true in JSON definitions. |
Height | 300 | Set it small, e.g. 24–48 px. |
Highlight (line, area) | none | PointHighlight.Last, First, Min, Max, combined with |. |
Interactive | true | False: plain SVG without JS (no tooltip). For many charts on a page. |
Width | the container | Needed for exact geometry when Interactive="false". |
AutoCompact | true | Leave out axis titles, legend, title and axis labels as a normal chart gets small. Also "autoCompact" in JSON definitions. |
KeyboardNavigation | off when compact | Set true to make a compact chart a tab stop with arrow-key navigation. |