Step 2: Creating the View Model

Create a new class named SaleViewModel. This will act as the DataContext for the View which will contain C1Chart.

public class SaleViewModel : INotifyPropertyChanged

{

    private ObservableCollection<Sale> _sales = new ObservableCollection<Sale>();

 

    public SaleViewModel()

    {

        //load data

        LoadData();

    }

 

    public ObservableCollection<Sale> Sales

    {

        get { return _sales; }

    }

 

    public void LoadData()

    {

        //TODO: load data from your data source

        _sales.Add(new Sale("Bikes", 23812.89, 12479.44));

        _sales.Add(new Sale("Shirts", 79752.21, 19856.86));

        _sales.Add(new Sale("Helmets", 63792.05, 16402.94));

        _sales.Add(new Sale("Pads", 30027.79, 10495.43));

    }

 

    public event PropertyChangedEventHandler PropertyChanged;

 

    void OnPropertyChanged(string propertyName)

    {

        if (PropertyChanged != null)

            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

    }

}

This class includes an ObservableCollection, Sales, as well as a method to generate mock data upon initialization.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.