Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Tooltips

Since 0.1.0-alpha.22
Each series' value for the item under the pointer or keyboard focus, said to screen readers, from a template of your own if you like.

A tooltip template

To write the tooltip yourself, put a ChartTooltip in the chart. Its context has the Item, the formatted Argument, and each series' Points with their names, values and colors.

Static

Preview

Revenue and costs, first half
  • Revenue
  • Costs
Arrow keys move between values; Escape hides the tooltip.

Code

Tooltips.razor
@* A tooltip template that adds the margin to each month's revenue and costs. *@
<Chart Items="_months" Argument="m => m.Month" Title="Revenue and costs, first half">
    <ChartValueAxis Format="C0" />
    <ChartBarSeries Value="m => m.Revenue" />
    <ChartBarSeries Value="m => m.Costs" />
    <ChartTooltip>
        <div class="ib-chart-tooltip-title">@context.Argument</div>
        @foreach (var point in context.Points)
        {
            <div class="ib-chart-tooltip-row">
                <span class="ib-chart-tooltip-key" style="background:@point.Color"></span>
                <span>@point.Series</span>
                <span class="ib-chart-tooltip-value">@point.Text</span>
            </div>
        }
        <Divider MarginY="1" />
        <TextBlock Size="TextSize.Sm" Color="Color.Muted">
            Margin @(((context.Item.Revenue - context.Item.Costs) / context.Item.Revenue).ToString("P1"))
        </TextBlock>
    </ChartTooltip>
</Chart>

@code {
    private record MonthTotals(string Month, decimal Revenue, decimal Costs);

    private readonly MonthTotals[] _months =
    [
        new("January", 42_100, 30_400),
        new("February", 45_800, 31_200),
        new("March", 51_300, 33_900),
        new("April", 48_700, 32_500),
        new("May", 55_200, 35_100),
        new("June", 58_900, 36_800),
    ];
}

To show the tooltips from the keyboard, Tab to the chart and use the arrow keys. A screen reader hears each value as they move.

The tooltip is rendered on the server with the page, so keep the template to text and inline content. To leave the tooltips out, set Tooltip to false. They're off by default when every series has value labels.

Connection lost

Rejoining the server…