How could i display a Graph on WindowsForms?

僤鯓⒐⒋嵵緔 提交于 2019-12-25 04:17:16

问题


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


回答1:


There is a nice tool un 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.




回答2:


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();
}


来源:https://stackoverflow.com/questions/38713649/how-could-i-display-a-graph-on-windowsforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!