Hi Martyn,
I had similar usecase, and sovled by involving manager viewmodel which has a reference
of chartView/chartViewModel. I'm not sure it would be helpful in your usecase,
but pls be refered. My usecase was to display line chart in real time with temperatures
of several parts of machine,which has unknown numer of sensor(2 ~ 5 EA per machine).
ViewModel can create multiple dynamic series if he has a refernce of RadChart,
so I have no chice to set this when creating chart viewmodel as such.
And then multiple series are created as follows;
// this was called whenever new temperature has beed arrived
// in his parent-parent manager object.
// ThermoHead : series business object of each part.
// When heat type is not yet created in series list,create it and bind.
private void UpdateHeat(int heatType, int heatTime, int heat)
{
ThermoHead series = _seriesList.SingleOrDefault(k => k.HeatType.Equals(heatType));
if (series == null)
{
// create series and add into colelction
series = new ThermoHead(heatType, PopTagTypeEnumsMapper.DisplayStringfromEnum((PopTagTypeEnums)heatType));
_seriesList.Add(series);
// add new series in chart
AddSeries();
}
// push heat data
series.HeatCollection.SuspendNotifications();
if (series.HeatCollection.Count > _maxCount)
series.HeatCollection.RemoveAt(0);
series.HeatCollection.Add(new SeriesData(DateTime.Now, heat));
series.HeatCollection.ResumeNotifications();
}
#region chart method
// _chart is reference of radChart .
internal void AddSeries()
{
foreach (var head in _seriesList)
{
// chk exists in chart
var exist = _chart.Series.SingleOrDefault(k => k.Name.Equals(head.HeatName));
if (exist != null)
continue;
LineSeries series = new LineSeries();
series.CategoryBinding = new PropertyNameDataPointBinding("TimeStamp");
series.ValueBinding = new PropertyNameDataPointBinding("Value");
series.Name = head.HeatName;
series.ItemsSource = head.HeatCollection;
_chart.Series.Add(series);
}
// my other method releted
CreateLegendColor(_chart.Series[0]);
RefreshChart();
}
public class ThermoHead
{
public int HeatType {get;set;}
public string HeatName {get;set;}
public RadObservableCollection<
SeriesData
> HeatCollection {get;set;}
public ThermoHead(int heatType, string typeName)
{
HeatType = heatType;
HeatName = typeName;
HeatCollection = new RadObservableCollection<
SeriesData
>();
}
}
public class SeriesData
{
private DateTime _timeStamp;
private decimal _value;
private string _category;
public SeriesData(DateTime timeStamp, decimal value)
{
this._timeStamp = timeStamp;
this._value = value;
}
public SeriesData(string category, decimal value)
{
this._category = category;
this._value = value;
}
public DateTime TimeStamp
{
get
{
return this._timeStamp;
}
set
{
if (this._timeStamp != value)
{
this._timeStamp = value;
}
}
}
public string Category
{
get
{
return this._category;
}
set
{
if (this._category != value)
{
this._category = value;
}
}
}
public decimal Value
{
get
{
return this._value;
}
set
{
if (this._value != value)
{
this._value = value;
}
}
}
}
I borrowed dynamic chart method in telerik's sample and just only add to create series in ViewModel instead of code behind.
RGDS
Kang