Page 1 of 1

Huge number of data display issue

Posted: Fri Nov 13, 2009 5:06 am
by 9529132
I have to display 6 series of data and each series may contain up to 4 million sampled data. To display the series, I can think of 2 ways. One is to plot all at once after all data are collected, and the other is to display N data each time CVICALLBACK EveryNCallback is triggered and append consecutive sets of N data. Would anyone please suggest which way is better? Any other way to plot such huge number of data? Any issues I need to take care like how to refresh?

And could anyone please comment which version, ActiveX or NET, of teechart is suitable in terms of refreshing speed to display large number of data?

Re: Huge number of data display issue

Posted: Mon Nov 16, 2009 8:59 am
by 9529132
Anyone? Please advice.

Re: Huge number of data display issue

Posted: Mon Nov 16, 2009 9:07 am
by yeray
Hi David,

First, please take a look at the Real-time Charting article here where some important performance hints are described.

I'd recommend you to make two simple test applications to simulate the final application (one with the .NET eval and one with the ActiveX eval) because the final performance will depend on the specific application needs. Here you have a performance test in both versions we made for another customer:

.NET performance test

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        int nrOfSamples = 10000;
        private Steema.TeeChart.Styles.FastLine fastline1;
        private Steema.TeeChart.Styles.FastLine fastline2;
        private System.Diagnostics.Stopwatch stopWatch;

        private void InitializeChart()
        {
            stopWatch = new System.Diagnostics.Stopwatch();

            tChart1.Aspect.View3D = false;
            tChart1.Aspect.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;

            fastline1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
            fastline2 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);

            //pre-assign ChartPens
            Pen rPen = new Pen(Color.Red);
            Pen bPen = new Pen(Color.Blue);
            Steema.TeeChart.Drawing.ChartPen redPen = new Steema.TeeChart.Drawing.ChartPen(tChart1.Chart, rPen);
            Steema.TeeChart.Drawing.ChartPen bluePen = new Steema.TeeChart.Drawing.ChartPen(tChart1.Chart, bPen);
            fastline1.LinePen = redPen;
            fastline2.LinePen = bluePen;

            fastline1.FillSampleValues(nrOfSamples);
            fastline2.FillSampleValues(nrOfSamples / 2);

            //tChart1.Axes.Left.SetMinMax(-5.0, 5.0);

            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            //calculate elapsed time
            //stopWatch.Stop();
            TimeSpan elapsedTime = stopWatch.Elapsed;
            string total = elapsedTime.TotalSeconds.ToString();
            label1.Text = "Elapsed time: " + total + " s";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;

            stopWatch.Reset();
            stopWatch.Start();

            tChart1.AutoRepaint = false;

            double[] x1 = new double[nrOfSamples];
            for (int i = 0; i < x1.Length; i++)
            {
                x1[i] = i;
            }
            double[] x2 = new double[nrOfSamples / 2];
            for (int i = 0; i < x2.Length; i++)
            {
                x2[i] = i;
            }
            double[] random1 = new double[nrOfSamples];
            double[] random2 = new double[nrOfSamples / 2];

            for (int i = 0; i < 100; i++)
            {
                FillArray(random1);
                FillArray(random2);
                fastline1.Add(x1, random1);
                fastline2.Add(x2, random2);
                tChart1.AutoRepaint = true;
                //tChart1.Refresh();
                Application.DoEvents();
            }
            stopWatch.Stop();
            button1.Enabled = true;
        }

        private static void FillArray(double[] myArray)
        {
            Random y = new Random();
            for (int i = 0; i < myArray.Length; i++)
            {
                myArray[i] = y.Next();
            }
        }
ActiveX performance test

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        int nrOfSamples = 10000;
        private System.Diagnostics.Stopwatch stopWatch;

        private void InitializeChart()
        {
            stopWatch = new System.Diagnostics.Stopwatch();

            axTChart1.Aspect.View3D = false;
            //tChart1.Aspect.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;

            axTChart1.AddSeries(TeeChart.ESeriesClass.scFastLine);
            axTChart1.AddSeries(TeeChart.ESeriesClass.scFastLine);

            axTChart1.Series(0).FillSampleValues(nrOfSamples);
            axTChart1.Series(1).FillSampleValues(nrOfSamples / 2);

            //axTChart1.Axis.Left.SetMinMax(-5.0, 5.0);

            axTChart1.OnAfterDraw += new EventHandler(axTChart1_OnAfterDraw);
        }

        void axTChart1_OnAfterDraw(object sender, EventArgs e)
        {
            //calculate elapsed time
            //stopWatch.Stop();
            TimeSpan elapsedTime = stopWatch.Elapsed;
            string total = elapsedTime.TotalSeconds.ToString();
            label1.Text = "Elapsed time: " + total + " s";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;

            stopWatch.Reset();
            stopWatch.Start();

            //axTChart1.AutoRepaint = false;

            double[] x1 = new double[nrOfSamples];
            for (int i = 0; i < x1.Length; i++)
            {
                x1[i] = i;
            }
            double[] x2 = new double[nrOfSamples / 2];
            for (int i = 0; i < x2.Length; i++)
            {
                x2[i] = i;
            }
            double[] random1 = new double[nrOfSamples];
            double[] random2 = new double[nrOfSamples / 2];

            for (int i = 0; i < 100; i++)
            {
                FillArray(random1);
                FillArray(random2);
                axTChart1.Series(0).AddArray(x1.Length, random1, x1);
                axTChart1.Series(1).AddArray(x2.Length, random2, x2);
                //tChart1.AutoRepaint = true;
                Application.DoEvents();
            }

            stopWatch.Stop();

            button1.Enabled = true;
        }

        private static void FillArray(double[] myArray)
        {
            Random y = new Random();
            for (int i = 0; i < myArray.Length; i++)
            {
                myArray[i] = y.Next();
            }
        }

Re: Huge number of data display issue

Posted: Mon Nov 16, 2009 9:55 am
by 9529132
Hi, Yeray,

Thanks for your post, and you have answered the second part of my question. Would you please also advice on the first part, as how to more effectively plot huge number of data?

David

Re: Huge number of data display issue

Posted: Mon Nov 16, 2009 10:43 am
by yeray
Hi David,

The slowest process with a lot of data is when this data is going to be drawn. That means that your application will be faster if you draw as few data as possible and refresh the chart as few times as possible.
So I'd recommend you to add all the data at the same time (with autorepaint=false) and paint your chart then.

Please, take a look at the article I mentioned above.