Click here to Skip to main content
15,921,622 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends I am trying RealTime example with VisualStudio using OxyPlot.I couldn understand WPF application ,could you help me ? This is very important to machine interface.

What I have tried:

C#
<pre lang="c#"> private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Interval = 100;
            timer1.Start();
            lastTimerTick = DateTime.Now;
            pv.Model.Title = "DateTime";

            pv.Model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -5, Maximum = 5 });

           
            pv.Model.Series.Add(lineSeries);
            pv.Model.InvalidatePlot(true);
            DateTime.UtcNow.AddTicks(0);
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            //double t0 = this.watch.ElapsedMilliseconds * 0.001;
            
            TimeSpan key = DateTime.Now - lastTimerTick;
            float t1 = (float)key.TotalMilliseconds / 1000;
            
            lineSeries.Points.Add(new DataPoint(i++,rnd.NextDouble()));

            textBox1.Text = t1.ToString();
            
            if (lineSeries.Points.Count > 20)
            {
                lineSeries.Points.RemoveAt(0);
            }
                
            pv.Refresh();
        }
Posted
Updated 11-Feb-18 21:11pm

1 solution

You probably need to use Dispatcher.CheckAccess() as the timer method is on another thread, see answers here: c# - InvokeRequired in wpf - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900