A minimal Windows Forms control for displaying sparkline graphs with real-time data updates and configuration options.
-
Data Handling
- Dynamic data point management (add/remove/clear)
- Automatic data truncation via
MaxDataPoints(10-1000 range) - Float-based values only
-
Visual Customization
- Configurable line color, width, and smoothing
- Optional data point markers
- Grid lines with color control
- Threshold line with value and color settings
-
Statistics Overlay
- Toggle visibility of min/max/average/median/range/standard deviation
- Position calculation relative to current data window
-
Design-Time Integration
- Property grid dropdown for graph selection
- Automatic form instance discovery
-
Configuration Properties
- Direct mapping to SparklineGraph properties
- Color pickers for line/grid/threshold elements
- Numeric inputs with range validation
- .NET Framework 4.7.2+ or .NET Core 3.1+
- Visual Studio 2019+ (for designer support)
-
Manual Inclusion
- Add
SparklineGraph.cs, and optionallySparklineGraphController.csandSparklineGraphEditor.csto your project - Build solution to enable toolbox items
- Add
-
Package Manager (Recommended)
Install-Package CuttySpark.WinForms
// Create and configure graph
var sparkline = new SparklineGraph {
Dock = DockStyle.Fill,
LineColor = Color.FromArgb(44, 123, 182),
MaxDataPoints = 150,
ShowStatistics = true
};
// Add initial data
sparkline.AddRange(new[] { 18.4f, 22.1f, 19.8f, 25.6f });
// Create controller
var controller = new SparklineGraphController {
Dock = DockStyle.Right,
SelectedGraph = sparkline
};
// Add to form
Controls.Add(sparkline);
Controls.Add(controller);- Immediate property synchronization
- Null-safe graph deselection
- Design-time validation of graph references
-
Uses double-buffering to reduce flicker
-
O(n) complexity for data updates
-
Statistics calculations cached during render
-
Batch updates are best performed with the
BeginUpdate()andEndUpdate()pattern, as shown below// Batch update pattern sparkline.BeginUpdate(); try { for (int i = 0; i < 500; i++) { sparkline.AddDataPoint(GenerateValue()); } } finally { sparkline.EndUpdate(); }
