Data binding is the core for any data visualization control. The Sparkline control can easily bind to any enumerable collection of data values i.e. to any class that implements the IEnumerable interface. Also, the class can implement the INotifyCollectionChanged interface to have support for modifying data after binding.
The topic describes how to add Sparkline control to your Windows Form application. This topic comprises following three steps:
The following image shows how the Sparkline control appears after completing the above steps.
In this step, you add a class to your project that returns an enumerable collection of numeric data points to be plotted on the Sparkline chart. This code example assumes that you add a class named SampleData.cs to return a collection of numeric values.
C# |
コードのコピー
|
---|---|
class SampleData { public List<double> Sales { get { List<double> data = new List<double>() { 1.0, -1.0, 2.0, -3.0, 4.0, 5.0, -5.0, 2.0 }; return data; } } } |
The SampleData.cs class added in the above step returns a collection of numeric values using the ‘Sales’ property defined in the class. In this step, you bind this collection to the Sparkline control so that data can be plotted at runtime. For this, you need to create an instance of the SampleData class and assign the value returned by the Sales property to Data property of Sparkline control.
C# |
コードのコピー
|
---|---|
SampleData sampleData = new SampleData();
c1Sparkline1.Data = sampleData.Sales;
|
Click Build | Build Solution to build the project. Run the application and observe how the C1Sparkline control appears at runtime.