7

i am a beginner at c#, so you could help me. At first, i get some data from a RS422 to USB converter over a COM Port and now i want to display over the right COM-Port the graph on the Screen. My Question: How could i display the Graph on my WindowsForms ?

Sorry for my english.

M.Spitz

M.Spitz
  • 81
  • 1
  • 1
  • 2

2 Answers2

10

There is a nice tool in Windows Forms called Chart. You can draw graphs of different kind with it.

Here is a Tutorial

Here is a Video that shows how to use it.

Here is a nice post with an example from StackOverflow.

Have fun exploring it.

Basically the steps are:

  1. Create a Series for each line you want to draw.

  2. Add the values from your array or list to the series.

EDIT: 3. See comment by TaW

EDIT 2) : here you find all different chart types that can be displayed.

and here how to use them.

When you click in the property window of the chart on Series you get the Series-Properties. There you can also find the property: ChartType and set it by a mouse click if you want to.

Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
  • 1
    For an oscillopsope effect step 3 is to remove DataPoints from the Left as new ones are coming in or moving the minimum and maximum vlaues for the x-axis. – TaW Aug 02 '16 at 07:21
  • Why not, it will display the point that you feed into it. If you have an array that contains the right values it will display it. See my edit – Mong Zhu Aug 02 '16 at 07:44
  • At first thank you guys:) Another Question, i hope you can help me also like the first one. How does the Chart knows the right COM-Port? I will give the user a selection of COM-Ports over a Dropdown Menu. – M.Spitz Aug 02 '16 at 07:47
  • 1
    the Chart won't know anything about a COM Port. It knows only about the numbers that you feed into it. This is your responsibility. – Mong Zhu Aug 02 '16 at 07:49
  • I wish you success! :) – Mong Zhu Aug 02 '16 at 08:19
1

You'll have to create the port object and set the necessary parameters for it from the design view search for port tool

or your code like this

dataPort.PortName = your_port_name;
dataPort.BaudRate = your_baud_rate;

After you open the port and read the data from it:

dataPort.Open();

while(dataPort.IsOpen)
{
    chart1.Series["Series1"].Points.AddXY(val.Second, dataPort.ReadByte());
    chart1.Update();
}
emalinga
  • 58
  • 6