This quick start guides you through the steps of creating a simple Sparkline application by populating its data from an enumerable collection.
The following example uses the temperatures recorded for eight consecutive days in Canada to visualize the temperature fluctuations in the area and the following output appears after executing the application.
XAML |
Copy Code
|
---|---|
xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml" |
Drag and drop the Sparkline control from Toolbox onto your MainWindow. The Sparkline control gets added to the application. Add a few basic properties of Sparkline using the following code.
XAML |
Copy Code
|
---|---|
<c1:C1Sparkline x:Name="sparkline" Height="250" Width="250"/> |
C# |
Copy Code
|
---|---|
public class SampleData { public List<double> DefaultData { get { List<double> data = new List<double>() { 1.0, -2.0, -1.0, 6.0, 4.0, -4.0, 3.0, 8.0 }; return data; } } } |
Switch to the MainWindow.xaml.cs file and bind Sparkline to the data source using Data property of the C1Sparkline class as shown in the following code snippet.
C# |
Copy Code
|
---|---|
public partial class MainWindow : Window { private SampleData sampleData = new SampleData(); public MainWindow() { InitializeComponent(); //Data binding using Data property sparkline.Data = sampleData.DefaultData; } } |