Welcome to the FoxLearn
Today we will learn how to use chart control
The Chart control visualizes your data
It displays data in your Windows Forms program as a bar graph or chart
With Chart you can quickly display your data in a colorful graphic controlled by C# code
First, You need to add a button and two chart control to Form1
You can add manual data to chart or dynamic load data from the database to chart
The first chart displays salary data and second chart display revenue data
Your chart display data from database when you click the load button
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 create a new database, then create a revenue table
Your application will read data from revenue table and display to chart control
We will use entity framework to get data from database
Entity Framework is an object-relational mapper that enables .NET developers to work with relational data using domain-specific objects
It eliminates the need for most of the data-access code that developers usually need to write
You can see the connection string auto generated in config file
A connection string contains initialization information that is passed as a parameter from a data provider to a data source
Connection strings used by the Entity Framework contain information used to connect to the underlying ADO.NET data provider that supports the Entity Framework
They also contain information about the required model and mapping files
You can easily change chart color or chart type
If the Palette property for both the Chart and Series objects is set to None, and no color is assigned to the relevant data series or data points
the data points will not be drawn, and will be displayed as "empty" areas.
Now we will change color for salary chart, each column is a different color
Thank you for watching this video
