예제 #1
0
        private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            timer1.Stop();

            Random rIdx = new Random(lineSeries1.Count);
            int    rnd  = 0;

            if ((idx1 < 1) && ((lineSeries1.LastVisibleIndex - lineSeries1.FirstVisibleIndex) > 40))
            {
                rnd  = rIdx.Next((int)((lineSeries1.LastVisibleIndex - lineSeries1.FirstVisibleIndex)));
                idx1 = lineSeries1.FirstVisibleIndex + rnd;
            }

            if (lineSeries1.Count > 360)
            {
                if (lineSeries1.XValues.Last > 540)
                {
                    if (deltaUp)
                    {
                        lineSeries1.Add(lineSeries1.XValues.Last + 1, lineSeries1.YValues.Last + r.Next(-5, 45));
                        if (lineSeries1.YValues.Last > 54)
                        {
                            deltaUp = false;
                        }
                    }
                    else
                    {
                        lineSeries1.Add(lineSeries1.XValues.Last + 1, lineSeries1.YValues.Last + r.Next(-45, 5));
                        if (lineSeries1.YValues.Last < -54)
                        {
                            deltaUp = true;
                        }
                    }
                }
                else
                {
                    lineSeries1.Add(lineSeries1.XValues.Last + 1, 100.0 * Math.Sin((lineSeries1.XValues.Last - 360) * Math.PI / 180));
                }
                lineSeries1.Delete(0, 1);
                idx1--;
                tChart1.Axes.Bottom.Scroll(1, false);
            }
            else
            {
                lineSeries1.Add(100.0 * Math.Sin(lineSeries1.Count * Math.PI / 180));
            }

            if (idx1 < lineSeries1.FirstVisibleIndex)
            {
                idx1 = -1;
            }

            timer1.Start();
        }
예제 #2
0
        private void addDataToChart(byte a, byte b, byte c, byte d)
        {
            timerDrawI++;
            red.Add(timerDrawI, a * 256 + b);
            blue.Add(timerDrawI, c * 256 + d);

            if (timerDrawI >= 1000)
            {
                red.Delete(0);
                blue.Delete(0);
            }
        }