在wpf应用程序上使用oxyplot在图上绘制一个点 [英] draw a point on a graph using oxyplot on wpf application
本文介绍了在wpf应用程序上使用oxyplot在图上绘制一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目中,我想在图表等于某个特定值时在实时图表上绘制一个点。
我不知道那是怎么回事。
这是我用来显示实时图的代码:
public class MainViewModel
{
public PlotModel DataPlot {get;组; }
public DispatcherTimer graphTimer;
private double _xValue = 10;
public MainViewModel()
{
DataPlot = new PlotModel();
DataPlot.Series.Add(new LineSeries());
graphTimer = new DispatcherTimer();
graphTimer.Interval = TimeSpan.FromMilliseconds(MainWindow.timerRefreshMs);
graphTimer.Tick + = dispatcherTimer_Tick;
graphTimer.Start();
$ b public void dispatcherTimer_Tick(object sender,EventArgs e)
{
ScatterSeries series = new ScatterSeries();
Dispatcher.CurrentDispatcher.Invoke(()=>
{
(DataPlot.Series [0] as LineSeries).Points.Add(new DataPoint(_xValue,MainWindow.z));
//DataPlot.InvalidatePlot(true);
// _ xValue ++;
if(MainWindow.z == 900)
{
// ADD A POINT
DataPlot.InvalidatePlot(true);
_xValue ++;
if((DataPlot.Series [0] as LineSeries).Points .Count> 80)//只显示10个最后点
(DataPlot.Series [0] as LineSeries).Points.RemoveAt(0); //删除第一个点
});
}
}
解决方案
int _xValue = 0;
public void dispatcherTimer_Tick(object sender,EventArgs e)
{
Dispatcher.CurrentDispatcher.Invoke(()=>
{
LineSeries ser = plotModel.Series [ 0]作为LineSeries;
if(ser!= null)
{
//检查您的条件并截断点的Y值
double yValue = 1; $ b $ (ser.Points.Count> 80)//只显示10个最后点$ b b $ b ser.Points.RemoveAt(0); //删除第一个点
plotModel.InvalidatePlot(true);
});
}
让我知道是否有任何问题无法解决。
In my project I want to draw a point on a real-time graph whenever the graph is equal to a certain value. I don't know how do that. This is the code that I use to show the real time graph:
public class MainViewModel
{
public PlotModel DataPlot { get; set; }
public DispatcherTimer graphTimer;
private double _xValue = 10;
public MainViewModel()
{
DataPlot = new PlotModel();
DataPlot.Series.Add(new LineSeries());
graphTimer = new DispatcherTimer();
graphTimer.Interval = TimeSpan.FromMilliseconds(MainWindow.timerRefreshMs);
graphTimer.Tick += dispatcherTimer_Tick;
graphTimer.Start();
}
public void dispatcherTimer_Tick(object sender, EventArgs e)
{
ScatterSeries series = new ScatterSeries();
Dispatcher.CurrentDispatcher.Invoke(() =>
{
(DataPlot.Series[0] as LineSeries).Points.Add(new DataPoint(_xValue, MainWindow.z));
//DataPlot.InvalidatePlot(true);
//_xValue++;
if(MainWindow.z == 900)
{
//ADD A POINT
}
DataPlot.InvalidatePlot(true);
_xValue++;
if ((DataPlot.Series[0] as LineSeries).Points.Count > 80) //show only 10 last points
(DataPlot.Series[0] as LineSeries).Points.RemoveAt(0); //remove first point
});
}
}
解决方案
You should use the following pattern for adding or removing data:
int _xValue = 0;
public void dispatcherTimer_Tick(object sender, EventArgs e)
{
Dispatcher.CurrentDispatcher.Invoke(() =>
{
LineSeries ser = plotModel.Series[0] as LineSeries;
if (ser != null)
{
// check your conditions and caclulate the Y value of the point
double yValue = 1;
ser.Points.Add(new DataPoint(_xValue, yValue));
_xValue++;
}
if (ser.Points.Count > 80) //show only 10 last points
ser.Points.RemoveAt(0); //remove first point
plotModel.InvalidatePlot(true);
});
}
Let me know if anything is not working.
这篇关于在wpf应用程序上使用oxyplot在图上绘制一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文