Tooltips
Since 0.1.0-alpha.22A 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
- Costs
Margin 27.8%
Margin 31.9%
Margin 33.9%
Margin 33.3%
Margin 36.4%
Margin 37.5%
| Month | Revenue | Costs |
|---|---|---|
| January | $42,100 | $30,400 |
| February | $45,800 | $31,200 |
| March | $51,300 | $33,900 |
| April | $48,700 | $32,500 |
| May | $55,200 | $35,100 |
| June | $58,900 | $36,800 |
Code
@* 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>
{
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.