I have a question about Telerik UI for WPF, i want to achieve a number of real-time monitoring curve, here is my code:
XAML: in UserControl)
<telerik:RadCartesianChart.SeriesProvider>
<telerik:ChartSeriesProvider Source="{Binding CurrentProject.CurrentSubProject.LineSeriesCollection}">
<telerik:ChartSeriesProvider.SeriesDescriptors>
<telerik:CategoricalSeriesDescriptor ItemsSourcePath="Points" ValuePath="Sales" CategoryPath="Time">
<telerik:CategoricalSeriesDescriptor.Style>
<Style TargetType="telerik:LineSeries">
<Setter Property="StrokeThickness" Value="2"/>
</Style>
</telerik:CategoricalSeriesDescriptor.Style>
</telerik:CategoricalSeriesDescriptor>
</telerik:ChartSeriesProvider.SeriesDescriptors>
</telerik:ChartSeriesProvider>
</telerik:RadCartesianChart.SeriesProvider>
Model:
private ObservableCollection<Line> _lineSeriesCollection = new ObservableCollection<Line>() { };
/// <summary>
/// 界面中线条集合的Model
/// </summary>
public ObservableCollection<Line> LineSeriesCollection
{
get
{
if (_lineSeriesCollection.Count == 0)
{
_lineSeriesCollection.Add(new Line(0, 15));
_lineSeriesCollection.Add(new Line(10, 25));
_lineSeriesCollection.Add(new Line(20, 35));
_lineSeriesCollection.Add(new Line(30, 50));
}
return _lineSeriesCollection;
}
}
///////Line Class:
/// <summary>
/// 界面的线条集合Model
/// 20170417
/// </summary>
public class Line : INotifyPropertyChanged
{
#region INotifyPropertyChanged Members
[field: NonSerialized]
public event PropertyChangedEventHandler PropertyChanged;
public virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
/// <summary>
/// 用于存储当前线条的数据信息(组件名称+组件次序+输出参数)
/// </summary>
public string[] SelectedComponentInfo=new string[3];
/// <summary>
/// 用于存储线条中点数据的单位
/// </summary>
public string Unit;
private ObservableCollection<ShowRealTimePoint> _points = new ObservableCollection<ShowRealTimePoint>();
/// <summary>
///线条集合
/// </summary>
public ObservableCollection<ShowRealTimePoint> Points
{
get
{
return _points;
}
set
{
if (_points != value)
{
_points = value;
OnPropertyChanged("Points");
}
}
}
private int minRange;
private int maxRange;
private System.Timers.Timer timer;
public Line(int minRange, int maxRange)
{
this._points = new ObservableCollection<ShowRealTimePoint>();
this.minRange = minRange;
this.maxRange = maxRange;
this.timer = new System.Timers.Timer();
this.timer.Interval = 1000;
this.timer.Elapsed += this.Timer_Elapsed;
this.timer.Start();
}
private static Random r = new Random();
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() =>
{
if (this.Points.Count > 50)
{
this.Points.RemoveAt(0);
}
this.Points.Add(new ShowRealTimePoint { Time = DateTime.Now, ParamValue = r.Next(0,100), });
}));
}
}
///////ShowRealTimePoint Class:properties:Time ,ParamValue
Actually, I'm referring to your example,but I cannot achieve the goal(my English is not good)
I ask you to help me see what the problem is,
Thank you very much.!!