Sparkline for UWP | ComponentOne
Sparkline for UWP Quick Start / Step 2 of 3: Adding Code
In This Topic
    Step 2 of 3: Adding Code
    In This Topic

    In this step, you will add code to specify the data to which the C1Sparkline control is bound.

    1. Right-click MainPage.xaml and select View Code from the list.
    2. Add the following code below the InitializeComponent() method to change the marker color, and to create the data for your C1Sparkline control:
    C#
    Copy Code
    sparkline.MarkersColor = Colors.DeepPink;
    List<double> data = new List<double>() { 1, -2, 3, 4};
                Sale = new Sales();
                Sale.Data = data;
               
                List<DateTime> dateTime = new List<DateTime>() { new DateTime(2013,11,1), new DateTime(2013,11,2), new DateTime(2013,11,4), new DateTime(2013,10,5) };
                Sale.DateAxis = dateTime;
                this.sparkline.DataContext = Sale;
    
    1. Next, add the following class below the code added in point no. 2:
    C#
    Copy Code
    public Sales Sale { get; set; }
    
    1. Add the following code to populate the Sparkline with data:
    C#
    Copy Code
    public class Sales
        {
            public List<double> Data{get;set;}
            public List<DateTime> DateAxis{get;set;}
            public Sales()
            {
                Data = new List<double>();
                DateAxis = new List<DateTime>();
            }
        }
    

    What You've Accomplished:

    In this topic, you added code to bind the C1Sparkline control to a data source.

    See Also