【问题标题】:draw a point on a graph using oxyplot on wpf application在 wpf 应用程序上使用 oxyplot 在图形上绘制一个点
【发布时间】:2017-02-03 09:45:32
【问题描述】:

在我的项目中,只要图形等于某个值,我就想在实时图形上绘制一个点。 我不知道该怎么做。 这是我用来显示实时图表的代码:

 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
        });
    }


}

【问题讨论】:

    标签: c# wpf graph oxyplot


    【解决方案1】:

    您应该使用以下模式来添加或删除数据:

        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);
            });
        }
    

    如果有任何问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多