[英]draw a point on a graph using oxyplot on wpf application
在我的項目中,每當圖形等於某個值時,我都希望在實時圖形上繪制一個點。 我不知道該怎么做。 這是我用來顯示實時圖形的代碼:
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
});
}
}
您應該使用以下模式來添加或刪除數據:
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);
});
}
讓我知道是否有任何問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.