Hi,
I want to use xaml for binding nested collections to the the RadChart. However I don't want to hard code each series mapping manually like the examples show when they make use of multiple datasources or collection index.
As I can draw N number of series on chart at a given time hence hard-coding the series is impractical. Therefore I wanted to know how to handle this case in the most elegant way, by purely using Xaml and databinding the following data structure.
Thanks,
Farhan
I want to use xaml for binding nested collections to the the RadChart. However I don't want to hard code each series mapping manually like the examples show when they make use of multiple datasources or collection index.
As I can draw N number of series on chart at a given time hence hard-coding the series is impractical. Therefore I wanted to know how to handle this case in the most elegant way, by purely using Xaml and databinding the following data structure.
public class Data : INotifyPropertyChanged
{
private double m_Value;
private int m_Period;
public event PropertyChangedEventHandler PropertyChanged;
public double Value
{
get
{
return m_Value;
}
set
{
if (m_Value == value)
return;
m_Value = value;
this.OnPropertyChanged("Value");
}
}
public int Period
{
get
{
return m_Period;
}
set
{
if (m_Period == value)
return;
m_Period = value;
this.OnPropertyChanged("Period");
}
}
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public class DataPointSeries : INotifyPropertyChanged
{
private ObservableCollection<
Data
> m_DataList;
public ObservableCollection<
Data
> DataList
{
get
{
return m_DataList;
}
set
{
m_DataList = value;
OnPropertyChanged("DataList");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public class ChartsViewModel
{
private ObservableCollection<
DataPointSeries
> m_DataPointSeriesCollection;
public ObservableCollection<
DataPointSeries
> DataPointSeriesCollection
{
get
{
return m_DataPointSeriesCollection;
}
set
{
m_DataPointSeriesCollection = value;
}
}
public void PopulateDataSeriesCollection()
{
DataPointSeriesCollection = new ObservableCollection<
DataPointSeries
>
{
new DataPointSeries
{
DataList = GetDataPoint(0)
},
new DataPointSeries
{
DataList = GetDataPoint(12.75)
},
new DataPointSeries
{
DataList = GetDataPoint(27.625)
},
new DataPointSeries
{
DataList = GetDataPoint(37.675)
},
new DataPointSeries
{
DataList = GetDataPoint(43.475)
}
};
}
public ObservableCollection<
Data
> GetDataPoint(double factor)
{
var dataList = new ObservableCollection<
Data
>()
{
new Data
{
Period = 2002,
Value = 15 + factor
},
new Data
{
Period = 2003,
Value = 25 + factor
},
new Data
{
Period = 2004,
Value = 35 + factor
},
new Data
{
Period = 2005,
Value = 55 + factor
},
new Data
{
Period = 2006,
Value = 65 + factor
},
new Data
{
Period = 2007,
Value = 75 + factor
}
};
return dataList;
}
}
Thanks,
Farhan