How do i add a chart to a window form?

Holdren, Drake 6 Reputation points
2022-03-07T20:11:57.793+00:00

I'm trying to create a real-time graph of variables I'm monitoring from a PLC. I want to use the chart in a vb windows form .net. I saw some examples online using the chart control. the chart control in visual studio 2022 is greyed out. I saw some notes for the 3.5 framework, installing this did not solve the problem.

Developer technologies Windows Forms
Developer technologies Visual Studio Other
Microsoft Security Microsoft Graph
{count} vote

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2022-03-07T20:50:37.023+00:00

    The Chart class from the Data Visualization library is the correct control to use. You didn't specify what framework you are targeting but if you have a .NET 4.x app then it should be fine. You just need to open the form you want to add it to in the designer and the control should be available. Note that VS 2022 is using a newer Winforms designer and may have issues with this control. The workaround depends upon how comfortable you are with Winforms designer.

    • Open the form in VS 2019 or earlier and use that designer to work with the form until the chart is set up. This is just so you can use the older designer and has no impact on the actual application requirements.
    • Edit the .designer.cs file and add the control field along with the basic control properties in the InitializeComponent method. In theory you can then open the designer normally and at least edit the properties using the Properties window.

    In either case you can host the control a Windows Forms app.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.