TCP Client Data Plot in Winform

Budhikakgsl

New member
Joined
Mar 10, 2021
Messages
4
Programming Experience
Beginner
I need to plot the data from the server in a GUI in client. I am getting the data from the server to the client on PC. What I am currently doing is getting the data to a text box and each text is put into a array and data is taken from the array and plot the graph.

Is there any other easy method I can follow ?

this is my current code.

C#:
private void rbch1_CheckedChanged(object sender, EventArgs e)
{
    timer1.Start();
    chart1.Series[0].Points.Clear();
}

private void Timer1_Tick(object sender, EventArgs e)
{
    t1 += timer1.Interval;
    if (rbch1.Checked == true)
    {
        channelone = new Thread(ch1);
        channelone.Start();
    }
}

public void ch1()
{
    if (rbch2.Checked == false)
    {
        chart1.Invoke((MethodInvoker)(() => chart1.Series[1].Points.Clear()));
    }
    String ch1 = txtdata.Text; ;
    String[] ch1y = ch1.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
    for (int a = 1; a < ch1y.Length - 1; a++)
    {
        chart1.Invoke((MethodInvoker)(() => chart1.Series[0].Points.AddXY(t1, Convert.ToDouble(ch1y[a]))));
        chart1.Invoke((MethodInvoker)(() => chart1.ChartAreas[0].AxisX.Minimum = double.NaN));
        chart1.Invoke((MethodInvoker)(() => chart1.ChartAreas[0].AxisX.Maximum = double.NaN));
        if (chart1.Series[0].Points.Count > sampelsize())
            chart1.Invoke((MethodInvoker)(() => chart1.Series[0].Points.RemoveAt(0)));
    }
}
 
Last edited by a moderator:
What's the point of the TextBoxes? Why can't you just go straight from the original source to the array?
Because it is the string data that comes and can not plot all the points in a given time.

if I modify the code as below,

C#:
private void ch1()
        {
           for (int a = 1; a < arr.Length; a++)
            {
                chart1.Invoke((MethodInvoker)(() =>
                chart1.Series[0].Points.AddXY(t1, arr[a])));
            }
        }

it doesn't draw anything on the chart.
 
Because it is the string data that comes and can not plot all the points in a given time.
That doesn't really make sense. If you can add the data to one control, i.e. a TextBox, then you can add it to another control, i.e. the Chart. If there is some genuine reason that the data can't go into the Chart then use a data structure that exists for the purpose of data storage. That is not a control, which are for data display and user interation.
 
If you can take the string from your input and put it into a textbox, and then turn around and parse the string that came from the textbox to build your chart, then you can parse the string as it comes from the input and directly build your chart.
 
Back
Top Bottom