Hi guys,
I'd like to create and populate a serie using the code behind.
I've created a timer triggered wpf application that every 500 milliseconds execute the following code:
private void timer_Tick(Object sender, EventArgs e)
{
var findSerie = sfChart.Series.Where(x => x.Name == "RealTime");
if (findSerie.Count() == 0)
{
realtime.Name = "RealTime";
RealTimeDataViewModel rtVM = new RealTimeDataViewModel();
realtime.ItemsSource = rtVM;
realtime.XBindingPath = "Speed";
realtime.YBindingPath = "Rate";
realtime.Interior = new SolidColorBrush(Colors.DarkGreen);
sfChart.Series.Add(realtime);
}
int index = (sfChart.Series["RealTime"].ItemsSource as RealTimeDataViewModel).RealTimeDatas.Count - 1;
if (index < 0)
{
index = 0;
(sfChart.Series["RealTime"].ItemsSource as RealTimeDataViewModel).RealTimeDatas.Add(new RealTimeData() { Speed = i.Millisecond, Rate = rnd.Next(0, 1000) });
}
else
{
RealTimeData rtd = (sfChart.Series["RealTime"].ItemsSource as RealTimeDataViewModel).RealTimeDatas.Last<RealTimeData>();
(sfChart.Series["RealTime"].ItemsSource as RealTimeDataViewModel).RealTimeDatas.Add(new RealTimeData() { Speed = rtd.Speed + 500, Rate = rnd.Next(0, 1000) });
}
}
where RealTimeData is a class
public partial class RealTimeData
{
public int Speed { get; set; }
public double Rate { get; set; }
}
and RealTimeDatas is an ObservableCollection of RealTimeData.
I'm not able to view my data on the sfchart.
Have you got any suggestions?
Regards.