1

So want to be able to pause and resume my chart and text box from updating when I click a button. Currently, now it just updates in real-time time. I have attached my code below, I've tried ResumeUpdates() and PauseUpdates() for chart but it does not work for the textboxes I have no idea. The data im getting is stored in an ArrayList with originally comes from a serial port

Edit: if I have initraph() within mmy button function and call it from there it calls it once and gets updated once.

first button click =chart and textboxes updates in realtime

second button click = chart and textboxes pause

third button click = chart and textboxes resume updating

enter image description here

 private void InitChart()
        {
            if (!b)
            {
                speedRecordChart.ChartAreas[0].AxisX.Maximum = 200;
                speedRecordChart.ChartAreas[0].AxisX.Minimum = 0;


                if (position.lat1 > 90)
                {

                    textBox_analLat.Text = position.latComp1 + position.lat1 / 100;
                }
                else
                {

                    textBox_analLat.Text = position.latComp1 + position.lat1;
                }

                if (position.lng1 > 180)
                {
                    textBox_analLong.Text = position.lngComp1 + position.lng1 / 100;
                }
                else
                {
                    textBox_analLong.Text = position.lngComp1 + position.lng1;

                }

                speedRecordChart.Series["Speed"].Points.Clear();


                for (int i = 0; i < totalSpeedList.Count() - 1; ++i)
                {
                    speedRecordChart.Series["Speed"].Points.AddY(totalSpeedList[i]);
                }

                Console.WriteLine("speedChart : " + totalSpeedList);


            }
            return;

        }

        /*****************************************for button**********/
        Boolean b = true;
        private void button_Resume_Click(object sender, EventArgs e)
        {

            if (b == true)
            {
                button_Resume.Text = "resume";

                //speedRecordChart.Series.ResumeUpdates();
                // serialPort1.Close();
                InitChart();

            }
            else
            {
                button_Resume.Text = "pause";
                // speedRecordChart.Series.SuspendUpdates();


                // serialPort1.Open();
            }


            b = !b;

        }


Cherios
  • 47
  • 7

0 Answers0