In this article I am trying to make a small demo and explain the concept of chart in C#.


Chart is a graphical representation of data, charts allow users to see what the result of various data is to better understand and predict current and future data.

Steps for creating demo project:-

1.       Create a new project New >> Project (give the appropriate name of project).

2.       Now by default show a form1, in form1 drag and drop a datagridview where add the information for chart.

3.       After added datagridview drag and drop the chart from toolbox.

4.       After adding chart Goto on its property and click on the series property open its dialog box and rename the series (I rename the series into StudentScore).

Working with chart in C#

5.       Now double click on the form1 and get the form load event.

6       After getting form load event write the code in the form load event.

 private void Form2_Load(object sender, EventArgs e)
 dataGridView1.Rows.Add("alex stewart", 24, 56);
 dataGridView1.Rows.Add("chris harris", 34, 76);
 dataGridView1.Rows.Add("frank smith", 21, 46);
 dataGridView1.Rows.Add("henry paul", 27, 66);
 dataGridView1.Rows.Add("lan bishop", 31, 59);
 for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
 {                  this.chart1.Series["StudentScore"].Points.AddXY(dataGridView1.Rows[i].Cells[0].Value.ToString(), Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value.ToString()));
 catch (Exception ex)
 MessageBox.Show("something is wrong");

 Code Description:-

1.       This is form load event.

5.       To  9. Add data in datagridview.

10.   This is forloop it will run while datagridview rows count.

11.   This line of code will add data in chart from datagridview.


Working with chart in C#


  Modified On Nov-30-2017 04:58:21 AM

Leave Comment