Sparkline
Namespace: Wisej.Web
Assembly: Wisej.Framework (4.2.0.0)
Displays a compact line, area, or bar chart without axes.
- C#
- VB.NET
public class Sparkline : Control
Public Class Sparkline
Inherits Control
Samples use absolute units. The newest MaxPoints samples are retained. Click is inherited from Control.
Example:
var chart = new Sparkline { ChartType = SparklineChartType.Area, MaxPoints = 60, ShowLastPoint = true };
chart.Values = new double[] { 12, 18, 14, 25, 20 };
this.Controls.Add(chart);
chart.Push(28);
Constructors
Sparkline()
Initializes an empty, nonfocusable sparkline with a 30-sample rolling window.
Properties
ChartType
SparklineChartType: Gets or sets the chart mode. The default is Line. (Default: Line)
DefaultSize
Size: Gets the default chart size of 140 by 48 pixels.
Focusable
Boolean: Gets or sets whether the chart can receive focus. The default is false. (Default: False)
LineColor
Color: Gets or sets a custom chart color. Color.Empty uses the theme's Tone color. (Default: Color [Empty])
LineWidth
Int32: Gets or sets line thickness in pixels. The default is 2. (Default: 2)
Throws:
- ArgumentOutOfRangeException The width is less than one.
Maximum
Nullable<Double>: Gets or sets the upper scale bound, or null for automatic scaling. (Default: null)
Throws:
- ArgumentOutOfRangeException The bound is nonfinite or is not greater than Minimum.
MaxPoints
Int32: Gets or sets the positive rolling-window capacity. The default is 30. (Default: 30)
Reducing capacity immediately discards the oldest excess samples.
Throws:
- ArgumentOutOfRangeException The capacity is less than one.
Minimum
Nullable<Double>: Gets or sets the lower scale bound, or null for automatic scaling. (Default: null)
Throws:
- ArgumentOutOfRangeException The bound is nonfinite or is not less than Maximum.
Example:
chart.Minimum = 0;
chart.Maximum = 100;
chart.Values = new double[] { -10, 40, 120 }; // Drawing is clipped; sample values are retained.
chart.Minimum = null; // Restores an automatic lower bound.
NoSamplesText
String: Gets or sets the localized override for the "No samples." text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
SamplesSummaryText
String: Gets or sets the localized override for the "{0} samples. Latest value: {1}." text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation. {0} is the sample count and {1} is the latest value. Used for the CLDR other category of the current UI culture. Literal braces can be written as {{ and }}.
SampleSummaryText
String: Gets or sets the localized override for the "{0} sample. Latest value: {1}." text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation. {0} is the sample count and {1} is the latest value. Used for the CLDR one category of the current UI culture. Literal braces can be written as {{ and }}.
ShowLastPoint
Boolean: Gets or sets whether the last line or area sample has a marker. The default is false. (Default: False)
A single sample always has a marker. Bar charts always accent the last bar.
Smooth
Boolean: Gets or sets whether line and area paths use smooth curves. The default is false. (Default: False)
Curves remain between neighboring sample values. Bars ignore this property.
TabStop
Boolean: Gets or sets tab navigation participation. The default is false. (Default: False)
Threshold
Nullable<Double>: Gets or sets the absolute level above which a threshold band is drawn, or null to hide it. (Default: null)
Throws:
- ArgumentOutOfRangeException The threshold is not finite.
Example:
chart.Minimum = 0;
chart.Maximum = 100;
chart.Threshold = 75; // Shades values above 75 without changing the scale.
chart.Threshold = null; // Hides the band.
Tone
SparklineTone: Gets or sets the semantic color. The default is Primary. (Default: Primary)
LineColor, when nonempty, overrides this color.
Values
Double[]: Gets a copy of the samples or replaces them, retaining the newest MaxPoints values.
Null clears the chart. Mutating the source array or returned copy does not affect the control.
Throws:
- ArgumentOutOfRangeException A sample is NaN or infinite.
Example:
chart.Values = new double[] { 10, 20, 15 };
var samples = chart.Values;
samples[0] = 12;
chart.Values = samples; // Assign the edited copy to update the chart.
Methods
Clear()
Removes all samples while preserving scale, style, and rolling-window settings.
OnPointHover(e)
Raises PointHover with a snapshot of the hovered sample.
| Parameter | Type | Description |
|---|---|---|
| e | SparklinePointEventArgs | Sample index and value. |
OnWebEvent(e)
Dispatches client events to their processing methods.
| Parameter | Type | Description |
|---|---|---|
| e | WisejEventArgs | Client event and payload. |
OnWebRender(config)
Serializes chart state and wires PointHover, including for derived controls without attached handlers.
| Parameter | Type | Description |
|---|---|---|
| config | Object | Client configuration. |
Push(value)
Appends a sample, discarding the oldest sample when the window is full.
| Parameter | Type | Description |
|---|---|---|
| value | Double | Finite absolute sample value. |
Throws:
- ArgumentOutOfRangeException The sample is NaN or infinite.
Example:
chart.MaxPoints = 3;
chart.Values = new double[] { 10, 20, 30 };
chart.Push(40); // Values now contains 20, 30, 40.
ResetValues()
Clears the samples, restoring the default Values property.
Events
PointHover
EventHandler<SparklinePointEventArgs> Occurs when the pointer enters a different sample's horizontal region.
Stale notifications received after the sample window changes are ignored. Notifications also reach overrides of OnPointHover when no event handler is attached.
Implements
| Name | Description |
|---|---|
| IUserData | Provides access to the UserData and Tag properties associated to the component implementing this interface. |
| IBindableComponent | Bindable components implement this interface. |
| IDropTarget | Controls that support drag & drop operations implement this interface. |
| IWisejComponent | All wisej components implement this interface. |
| IWisejControl | All wisej controls derived from the Control class must implement this interface. |
| IWisejSerializable | Allows an object to serialize itself. |