Exemplo n.º 1
0
        const int DataSizeBase = 5000; //Increase this number to plot more points

        private void PlotData(bool reverse = false)
        {
            //Series 1 used primary YAxis
            Series Ser1 = chart1.Series[0];

            //Series 2 used secondary YAxis
            Series Ser2    = chart1.Series[1];
            Series Ser3    = chart1.Series[2];
            double angFreq = 0.20;

#if Dynamic
            int HalfSize = DataSizeBase / 10 * 9;
            for (int x = 0; x < HalfSize; x++)
            {
#if BUFFER
                Ser2.AddXYBuffered(x, 10 * Math.Cos(Math.PI * angFreq * x));
#endif
                Ser1.Points.AddXY(x, 10 * Math.Cos(Math.PI * angFreq * x));
            }
            for (int x = HalfSize; x < DataSizeBase; x++)
            {
#if BUFFER
                Ser2.AddXYBuffered(HalfSize + 20 * (x - HalfSize), 10 * Math.Cos(Math.PI * angFreq * x));
#endif
                Ser1.Points.AddXY(HalfSize + 20 * (x - HalfSize), 10 * Math.Cos(Math.PI * angFreq * x));
            }
#else
            for (int x = 0; x < DataSizeBase; x++)
            {
#if BUFFER
                Ser2.AddXYBuffered(2 * Math.PI * angFreq * x, 10 * Math.Cos(Math.PI * angFreq * x));
#endif
                Ser1.Points.AddXY(2 * Math.PI * angFreq * x, 10 * Math.Cos(Math.PI * angFreq * x));
            }
#endif

#if BUFFER
            Ser2.PlotBufferedData();
#endif
            var chartArea = chart1.ChartAreas.First();
            chartArea.AxisX.IsReversed = reverse;
            chartArea.AxisY.IsReversed = reverse;

            Series ptrSeries = chart2.Series[0];
            ptrSeries.Points.AddXY(1, 1);
            ptrSeries.Points.AddXY(2, 2);
            ptrSeries.Points.AddXY(3, 3);

            //Date Time Series
            Series   dateSeries = chart3.Series[0];
            DateTime today      = DateTime.Today;
            for (int x = 0; x < 10; x++)
            {
                dateSeries.Points.AddXY(today.AddDays(x), x);
            }
        }
Exemplo n.º 2
0
        private void randomDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ClearData();
            StartStopWatch();
            //Series 1 used primary YAxis
            Series Ser1 = chart1.Series[0];

            //Series 2 used secondary YAxis
            Series Ser2 = chart1.Series[1];

            Random rand = new Random();
            double data = 0;

            for (int x = 0; x < DataSizeBase; x++)
            {
                data += rand.NextDouble() - 0.5;
#if BUFFER
                Ser2.AddXYBuffered(x, data);
#endif
                Ser1.Points.AddXY(x, data);
            }
#if BUFFER
            Ser2.PlotBufferedData();
#endif
            Application.DoEvents();
            CheckStopWatch("Plot random datas");
        }