Tooltips
Tooltips and a crosshair that follow the pointer, with your own Razor in the tooltip when you need it. The chart sends its points to the browser once per layout and the tooltip follows the pointer there without calling .NET (unless the chart has a tooltip template), so charts stay responsive on Blazor Server too.
Custom tooltip text
TooltipValue on a series and TooltipHeader on the chart replace the text of the value and the header.
They get the hovered point (X, Y, Item, Items, the default text) and run once per
layout, not on pointer moves, so the tooltip stays fully in the browser. Return null to keep the default.
Code
<RioChart TItem="Reading" TooltipHeader="@(p => p.X is DateTime t ? t.ToString("dddd HH:mm") : null)">
<LineSeries Items="web" Name="Web" XValue="r => r.Time" YValue="r => r.Value"
TooltipValue="@(p => $"{p.Y:#,0} sessions ({p.Y - app[p.Index].Value:#,0} more than the app)")" />
<LineSeries Items="app" Name="App" XValue="r => r.Time" YValue="r => r.Value" Format="#,0 'sessions'" />
</RioChart>Tooltip template
TooltipTemplate renders any Razor inside the tooltip card. Its context has the Header, the
X value and the hovered Points, each with its items. The built-in classes (rio-tooltip-head,
-row, -dot, -name, -value) keep the default look.
The crosshair still follows the pointer in the browser, but the content is rendered by .NET when the hovered x changes: on Blazor
Server it lags one round trip behind. Prefer TooltipValue and TooltipHeader when text is enough.
Code
<RioChart TItem="Ticket" Items="tickets">
<ChildContent>
<BarSeries Name="Handling time" XValue="t => t.Topic" YValue="t => t.Minutes" Aggregate="Aggregate.Sum" />
</ChildContent>
<TooltipTemplate>
<div class="rio-tooltip-head">@context.Header: @context.Points[0].Items.Count tickets</div>
@foreach (var ticket in context.Points[0].Items)
{
<div class="rio-tooltip-row">
<span class="rio-tooltip-name">@ticket.Subject</span>
<span class="rio-tooltip-value">@ticket.Minutes min</span>
</div>
}
</TooltipTemplate>
</RioChart>Tooltip from code
ShowTooltipAsync(x) shows the crosshair and tooltip at an x value as if the pointer were there, and linked charts follow;
HideTooltipAsync() hides it. Here, hovering a row of the table points it out in the chart.
| Day | Orders |
|---|---|
| Tue 10 Nov | 222 |
| Wed 11 Nov | 233 |
| Thu 12 Nov | 249 |
| Fri 13 Nov | 260 |
| Sat 14 Nov | 258 |
| Sun 15 Nov | 262 |
| Mon 16 Nov | 273 |
Code
<RioChart @ref="chart" TItem="Reading" Items="orders">
<LineSeries Name="Orders" XValue="r => r.Time" YValue="r => r.Value" />
</RioChart>
@foreach (var day in orders)
{
<tr @onmouseenter="() => chart.ShowTooltipAsync(day.Time)" @onmouseleave="() => chart.HideTooltipAsync()">…</tr>
}