繁体   English   中英

在WPF应用程序上使用oxyplot在图形上画点

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM