Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have developed an application which will retrieve data from a SQL table. The table will have two columns. One column is a number and another one is the time. In the first column i can have same number repeated number of times.

When i execute the program, the table data is displaying in the datagrid view in a c# windows form.

Now My requirement is when i press a button,the data in the first column should be displayed in a pie chart or bar diagram based on the repeatition of the value in the column.

For example, in the first column i have 400 number for 8 times and 300 number for 2 times. SO when i click a button it should be displayed in a diagram like 400 is 80% and 300 is 20 %.

Data table example is like below link:-

Datagrid — imgbb.com[^]

What I have tried:

My code to retrieve the data and display in datagridview is as like below:-

C#
conn.Open();
cmd = new SqlCommand(sql, conn);
SqlDataAdapter adapter = new SqlDataAdapter();
DataTable dt = new DataTable();
adapter.SelectCommand = cmd;
adapter.Fill(dt);
cmd.Dispose();
conn.Close();
dataGridView1.DataSource = dt;
Posted
Updated 23-Jun-17 2:24am
v2

1 solution

See: Getting Started with Chart Controls[^]
Or if you want to create your own control: Create Pie Chart Using Graphics in C# .NET[^]
It's even possible to do some charting in the datagridview itself, see CodeProject article: DataGridView Gantt Style Chart Using C# WinForm [^]
 
Share this answer
 
v3
Comments
Krishna Chaitanya Bezawada 27-Jun-17 2:55am    
Hi, Thanks for your help.

I have used and applied that to my Program. The thing is, if i have 411.1 3 times in the table i am getting 3 times 411.1 in the pie diagram. But i need 411.1 to display 1 time only with 100% chart. If i have some other values then % should vary. Can you help with that?
RickZeeland 27-Jun-17 3:50am    
If you use an SQL query maybe you can use SELECT DISTINCT to select only unique values.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900