Welcome to FoxLearn
In this video, i'll show you how to create a line chart using chart control in Visual Studio
We will create a window form project, then drag Button, DataGridView and Chart controls from the Visual Studio Toolbox into your form designer.
You can design a simple windows forms application allows you to enter data, then draw line charts from your data
I will create a temperature class to store the data i add from the DataGridView.
This temperature class will contain the location name property, as well as the 12-month temperature.
I will also create an indexer to help me get the property value from the property name.
Indexers allow instances of a class or struct to be indexed just like arrays.
The indexed value can be set or retrieved without explicitly specifying a type or instance member.
Indexers resemble properties except that their accessors take parameters.
After you finish creating the temperature class, you need to rebuild your project.
Next open your form designer, select your DataGridView, then add a BindingSource to your DataGridView.
The BindingSource component is designed to simplify the process of binding controls to an underlying data source.
The BindingSource component acts as the data source for some or all of the controls on the form.
You can bind the BindingSource component to both simple data sources,
like a single property of an object or a basic collection like ArrayList,
and complex data sources, like a database table.
You need to add a click event handler on the Generate button that allows you to handle reading data from the DataGridView control,
then plot your chart as a line.
The chart control control contains two important properties of the Chart class are the Series and ChartAreas properties, both of which are collection properties.
The Series collection property stores Series objects,
which are used to store data that is to be displayed, along with attributes of that data.
The ChartAreas collection property stores ChartArea objects,
which are primarily used to draw one or more charts using one set of axes.
We will set the min and max values for the X and Y axes.
Where the X axis represents the month value, and the Y axis represents the temperature value.
We will loop all the rows on the grid, then draw lines from the temperature object data with random colors.
Each time the Generate button is pressed, you can see a chart drawn in different colors.
The line chart will show the temperatures in different locations.
Thank you for watching this video and don't forget to subscribe to my channel