Annotations
Mark what matters on a chart: target lines, campaign periods, maintenance windows and events. Muted by default, so they support the data.
Lines, bands, points and callouts
Reference lines expand the axis so they are always visible; bands do not. Values can be numbers, times or category names. Here an evening sale and a night-time maintenance window are bands on the time axis, the traffic target is a line, and the peak and the newsletter are marked on the data. Hover an annotation for its value.
Clicked: nothing yet (click an annotation)
Code
<RioChart TItem="Reading" YAxis="@(new AxisOptions { Title = "Sessions per 15 min" })" OnAnnotationClick="e => clicked = e.Label">
<ReferenceLine Value="200" Label="Target" />
<ReferenceBand Axis="AnnotationAxis.X" From="saleStart" To="saleEnd" Label="Evening sale" />
<ReferenceBand Axis="AnnotationAxis.X" From="maintenanceStart" To="maintenanceEnd" Label="Maintenance" Color="#d9480f" />
<ReferenceLine Axis="AnnotationAxis.X" Value="now" Label="Now" />
<PointAnnotation X="peak" Y="252" Label="Peak: 252 sessions" Color="#d9480f" />
<Callout X="newsletterSent" Y="34" Label="Newsletter sent" OffsetX="-30" OffsetY="-36" />
<LineSeries ... />
</RioChart>Draggable threshold
With Draggable, the user can move a reference line; @bind-Value receives the new value. Here it sets when to send a high-traffic alert.
Alert at 220 sessions per 15 min. Drag the dashed line.
Code
<ReferenceLine @bind-Value="alertAt" Label="Alert" Draggable="true" />
@code { double alertAt = 220; }Pins: click a point to add one, click the pin to remove it
OnPointClick gives the item behind a point, so pinning it is a PointAnnotation at its x and y.
With OnAnnotationClick set, point annotations and callouts are buttons: a click on the pin (its marker or
label) raises OnAnnotationClick even though the pin sits on a data point, so removing a pin is a click on the pin.
Click a point to pin it.
Code
<RioChart TItem="Reading" Items="orders" OnPointClick="Pin" OnAnnotationClick="Unpin">
<LineSeries Name="Orders" XValue="r => r.Time" YValue="r => r.Value" />
@foreach (var pin in pins)
{
<PointAnnotation @key="pin.Time" Id="@PinId(pin)" X="pin.Time" Y="pin.Value ?? 0" Label="@($"{pin.Value:0}")" />
}
</RioChart>
@code {
List<Reading> pins = [];
static string PinId(Reading r) => "pin-" + r.Time.Ticks;
void Pin(PointClickEventArgs<Reading> e) { if (e.Item is { } item && !pins.Contains(item)) pins.Add(item); }
void Unpin(AnnotationClickEventArgs e) => pins.RemoveAll(p => PinId(p) == e.AnnotationId);
}