Lines and areas
Line and area charts for time series in Blazor: three curve shapes, gaps for missing values, and areas that start at zero. The x axis can also be plain numbers.
Curves
Linear (default), Monotone (smooth, never overshoots the data) and Step (each value holds until the next point, for limits, prices and states). Here web sessions, and the server capacity that is scaled up for the day and down at night.
Code
<LineSeries Items="web" Name="Web sessions" XValue="r => r.Time" YValue="r => r.Value" Curve="CurveType.Monotone" />
<LineSeries Items="capacity" Name="Capacity" XValue="r => r.Time" YValue="r => r.Value" Curve="CurveType.Step" />Gaps
A null y value breaks the line instead of dropping to zero: here the conversion rate is missing for a few hours while tracking was down. A point with no neighbour gets a small dot so it stays visible.
Code
<RioChart Items="conversion" YAxis="@(new AxisOptions { Title = "%" })">
<LineSeries Name="Conversion" XValue="r => r.Time" YValue="r => r.Value" Format="0.00 '%'" /> @* Value is double? *@
</RioChart>Irregular time series
Points are placed at their real times, so series do not need a fixed interval or the same timestamps, and the items need not be sorted: the chart sorts numbers and times by x itself (clicks and tooltips still give the right item). Here the stock of a product is logged only when it has moved by 3 items, or after an hour without a reading (53 readings: many while it sells fast and when a delivery comes in, few at night), and the reorder level is a step line that changes at irregular times. Hover a stock reading: the tooltip also lists the reorder level in effect at that moment, marked on the step line at the point where that level was set.
A long silence is not a gap by itself: the warehouse system was offline 13:10–15:05 and the line simply joins the readings on
either side. To break the line, add a reading with a null value where the data stops (see Gaps above).
Code
@* Readings logged on change: no fixed interval, different timestamps per series. *@
<RioChart TItem="Reading" YAxis="@(new AxisOptions { Title = "Items" })">
<LineSeries Items="stock" Name="Stock" XValue="r => r.Time" YValue="r => r.Value" Format="0 'in stock'" />
<LineSeries Items="reorderLevel" Name="Reorder level" XValue="r => r.Time" YValue="r => r.Value" Format="0" Curve="CurveType.Step" />
</RioChart>Dots on the points
Lines hide their points until hovered. With few readings, Highlight="PointHighlight.All" puts a dot on every
point, so it is clear where the values are and where the line only joins them. MarkerSize sets the dot's
diameter. Other PointHighlight values mark single points: first, last, lowest and highest (combine with
|). Beyond 1000 visible points All draws no dots. In JSON definitions: "highlight": "all".
Code
<RioChart TItem="Reading">
<LineSeries Items="checks" Name="Response time" XValue="r => r.Time" YValue="r => r.Value" Highlight="PointHighlight.All" />
</RioChart>Dashed and dotted lines
Dash="LineDash.Dashed" or LineDash.Dotted tells a forecast, plan or target apart from the actual
values, also without color. The pattern scales with StrokeWidth and the legend shows it too. On an
AreaSeries it dashes the top line and keeps the fill. Here the orders of the last weeks, a dashed forecast for the
next two and a dotted target. In JSON definitions: "dash": "dashed".
Code
<RioChart TItem="Reading">
<LineSeries Items="orders" Name="Orders" XValue="r => r.Time" YValue="r => r.Value" />
<LineSeries Items="forecast" Name="Forecast" XValue="r => r.Time" YValue="r => r.Value" Dash="LineDash.Dashed" />
<LineSeries Items="target" Name="Target" XValue="r => r.Time" YValue="r => r.Value" Dash="LineDash.Dotted" />
</RioChart>Numbers on the x axis
The x values do not have to be times: when XValue returns a number, the x axis is a linear number axis with nice
ticks, and everything else works the same (curves, gaps, zoom, the tooltip, reference lines). Here a load test: the response
time at each step from 10 to 500 concurrent users. The 95th percentile stays under the 120 ms limit up to about 350 users, then
climbs steeply as the servers saturate. XAxis takes a title and a Format for the tick labels, and the
vertical ReferenceLine with Axis="AnnotationAxis.X" marks the expected peak load.
Code
@* public record LoadStep(double Users, double MedianMs, double P95Ms); *@
<RioChart Items="loadTest" XAxis="@(new AxisOptions { Title = "Concurrent users", Format = "0" })"
YAxis="@(new AxisOptions { Title = "Response time, ms" })">
<LineSeries Name="Median" XValue="s => s.Users" YValue="s => s.MedianMs" Format="0 ms" Curve="CurveType.Monotone" />
<LineSeries Name="95th percentile" XValue="s => s.Users" YValue="s => s.P95Ms" Format="0 ms" Curve="CurveType.Monotone" />
<ReferenceLine Value="120" Label="Limit" />
<ReferenceLine Axis="AnnotationAxis.X" Value="300" Label="Expected peak" />
</RioChart>Areas
Areas always include zero, with a light fill under the line.
Code
<RioChart Items="revenue" YAxis="@(new AxisOptions { Title = "€ per 15 min" })">
<AreaSeries Name="Revenue" XValue="r => r.Time" YValue="r => r.Value" Format="#,0 €" Curve="CurveType.Monotone" />
</RioChart>Negative values
Values below zero need nothing extra: the y axis takes in the lowest value and zero, and an area fills from zero up or down.
Here the net cash flow per day: sales bring money in every day, supplier invoices on the 1st and 15th and wages on the 25th
take it out. A ColorBands entry with Below = 0 colors the outflow red, line and fill, exactly where
the line crosses zero.
Code
<RioChart Items="netCashFlow" YAxis="@(new AxisOptions { Title = "k€ per day" })">
<AreaSeries Name="Net cash flow" XValue="r => r.Time" YValue="r => r.Value" Format="+#,0.0 k€;−#,0.0 k€;0 k€"
ColorBands="@([new ColorBand { Below = 0, Color = "--rio-negative" }])" />
</RioChart>Colors by value
ColorBands colors a line by its value: here response times turn red above 120 ms, exactly where the line crosses
the limit, also between two readings. Bands take Above, Below or both; later bands win where they
overlap. On areas the fill follows, on bars and scatter points each one takes the color of its band, and the tooltip dot
matches. In JSON definitions: "colorBands": [{ "above": 120, "color": "--rio-negative" }].
Code
<RioChart Items="responseTimes">
<LineSeries Name="Checkout" XValue="r => r.Time" YValue="r => r.Value" Format="0 ms"
ColorBands="@([new ColorBand { Above = 120, Color = "--rio-negative" }])" />
<ReferenceLine Value="120" Label="Limit" />
</RioChart>Stacked areas
Series with the same Stack name are stacked: sessions by channel add up to the total. Hide one in the legend and the stack closes up.
Code
<RioChart TItem="Reading" YAxis="@(new AxisOptions { Title = "Sessions per 15 min" })">
<AreaSeries Items="search" Name="Search" XValue="r => r.Time" YValue="r => r.Value" Stack="channels" />
<AreaSeries Items="social" Name="Social" XValue="r => r.Time" YValue="r => r.Value" Stack="channels" />
<AreaSeries Items="email" Name="Email" XValue="r => r.Time" YValue="r => r.Value" Stack="channels" />
</RioChart>Range areas
RangeAreaSeries fills a band between a low and a high value per x: here the lowest and highest revenue on each date over
the last three years, around the average line. The tooltip shows "low – high". In a JSON definition it is "type": "rangeArea"
with "low" and "y" fields; with timeBucket the band keeps the lowest low and highest high.
Code
<RioChart Items="revenueHistory" YAxis="@(new AxisOptions { Title = "Revenue per day" })">
<RangeAreaSeries Name="Last 3 years" XValue="d => d.Date" LowValue="d => d.Low" HighValue="d => d.High"
Format="#,0 €" Curve="CurveType.Monotone" />
<LineSeries Name="Average" XValue="d => d.Date" YValue="d => d.Average" Format="#,0 €" Curve="CurveType.Monotone" />
</RioChart>Edge cases
Empty data, a single point and all-equal values each render a clean state, never an error or a collapsed axis.
Code
<RioChart TItem="Reading" Title="Empty"><LineSeries Items="empty" ... /></RioChart>
<RioChart TItem="Reading" Title="One point"><LineSeries Items="one" ... /></RioChart>
<RioChart TItem="Reading" Title="All equal"><LineSeries Items="flat" ... /></RioChart>