Skip to main content

Sparkline

Wisej.NET 4.2.0+

Three sparklines in an operations table: a line with its last point marked, an area with a threshold band, and bars.

A Sparkline is a word-sized chart: a line, an area or a row of bars with no axes, no legend and no labels, drawn to show the shape of a series at a glance. It sits beside a number in a table row, a card or a status bar and answers "which way is this going" without taking the space of a full chart.

The control keeps a rolling window of samples. Assign the whole series at once with Values, or append readings one at a time with Push, and the oldest samples drop out once the window holds MaxPoints of them, which makes it a natural fit for live counters such as orders per hour or queue length. When the trend needs axes, a legend or more than one series, use the ChartView instead; a KpiPanel can show a sparkline under its headline metric.

info

For a complete list of properties, methods, and events, see the API documentation.

Features​

Samples and the Rolling Window​

Values is an array of double. Reading it returns a copy and assigning it replaces the samples, keeping only the newest MaxPoints of them (30 by default). Push appends one sample and discards the oldest when the window is full; Clear removes them all while keeping the scale and the style. Samples must be finite numbers: NaN and infinity are rejected.

Chart Modes​

ChartType selects Line (the default), Area or Bar. Smooth turns line and area paths into curves, LineWidth sets the stroke, and ShowLastPoint puts a marker on the newest sample of a line or area. Bar charts always accent the last bar.

Scale and Threshold​

Without bounds the chart scales to the samples it holds. Minimum and Maximum fix the scale instead, which keeps several sparklines comparable to one another, for example the CPU load of three servers on a 0–100 scale; samples outside the bounds are clipped in the drawing and kept as data. Threshold shades the band above an absolute level without changing the scale, so a line that climbs into the band reads as a warning.

Color​

Tone picks a semantic theme color: Neutral, Primary (the default), Success, Warning or Danger. LineColor overrides it with an explicit color.

Events​

PointHover is raised when the pointer moves onto a different sample. Its SparklinePointEventArgs carries the Index of the sample in the displayed window and its Value. Click is inherited from Control.

The sparkline is not focusable and not a tab stop by default, since it is usually read next to the number it illustrates. For screen readers it announces the sample count and the latest value; SampleSummaryText, SamplesSummaryText and NoSamplesText override that text.

How To​

Show a Fixed Series​

this.sparklineRevenue.ChartType = SparklineChartType.Area;
this.sparklineRevenue.Tone = SparklineTone.Success;
this.sparklineRevenue.Smooth = true;
this.sparklineRevenue.Values = dailyRevenue.Select(d => (double)d.Amount).ToArray();

Stream Live Readings​

Push a reading on every tick. With MaxPoints at 60 and a one-minute timer, the chart always shows the last hour.

this.sparklineOrders.MaxPoints = 60;
this.sparklineOrders.ShowLastPoint = true;

this.timerOrders.Interval = 60000;
this.timerOrders.Tick += (s, e) =>
{
var count = orderService.CountOrdersInLastMinute();
this.sparklineOrders.Push(count);
this.labelOrders.Text = count.ToString("N0");
};
this.timerOrders.Start();

Flag a Backlog over Its Limit​

this.sparklineBacklog.ChartType = SparklineChartType.Area;
this.sparklineBacklog.Minimum = 0;
this.sparklineBacklog.Maximum = 100;
this.sparklineBacklog.Threshold = 60; // shades the band above 60 open tickets
this.sparklineBacklog.Tone = backlog.Last() > 60 ? SparklineTone.Danger : SparklineTone.Primary;
this.sparklineBacklog.Values = backlog;

Show the Hovered Sample​

private void sparklineOrders_PointHover(object sender, SparklinePointEventArgs e)
{
var minutesAgo = this.sparklineOrders.Values.Length - 1 - e.Index;
this.labelHover.Text = $"{e.Value:N0} orders, {minutesAgo} min ago";
}

Advanced​

JavaScript Widget​

ItemDescription
Class name"wisej.web.Sparkline"
Theme appearance"sparkline", see Themes. The "neutral", "primary", "success", "warning" and "danger" states set the chart color for each Tone.
Child components"chart" is the HTML host of the rendered SVG. See JavaScript.