Click here to Skip to main content
15,905,913 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello please help me. I want to make from dataGrid Table to Chart

this is my method for dataGrid :
C#
        DataSet ds = new DataSet();
    
        MySqlDataAdapter  daProfit = new MySqlDataAdapter();

public void FillDataGridProfit()
        {
            DataGridViewRow rowProfit = this.dgProfit.RowTemplate;
            rowProfit.DefaultCellStyle.BackColor = Color.Bisque;
            
            MySqlCommand slctProfit = new MySqlCommand("SELECT sum(value),name,IdUser FROM PROFITVIEW  where IdUser = '" + this.user.IdUser + "' group by name order by sum(value)", connection);

            daProfit.SelectCommand = slctProfit;
            daProfit.Fill(ds, "tblProfit");
            dgProfit.DataSource = ds.Tables["tblProfit"];
          
        }

I want my chart have "Sum(value)" , "name" for X , Y .
This is for C# Form.

Thanks :)
Posted
Updated 2-Sep-12 8:56am
v2
Comments
Wendelius 2-Sep-12 14:57pm    
Do you get an error or some other problem?
kespinko 2-Sep-12 14:58pm    
No My dataGrid work perfect but I dont know how to give a chart from this dataGrid :) I dont know how to work with chart controls

Here's few quite good tutorials:
- http://www.dotnetperls.com/chart[^]
- http://msdn.microsoft.com/en-us/library/dd489237.aspx[^]
- http://msdn.microsoft.com/en-us/library/dd489238.aspx[^]

Note that the example is adding static values as points, which isn't what you want. You can use the datatable as a DataSource[^] for the chart.

Off-topic: You shouldn't concatenate the values directly into the SQL statement. This leaves you open to SLQ injections, data type conversion problems etc. Instead, use MySqlParameter[^]
 
Share this answer
 
Comments
Manas Bhardwaj 3-Sep-12 6:23am    
yup +5
Wendelius 4-Sep-12 16:42pm    
Thanks :)
I would like to share another method since it use a free dataexport component to realize it:

See details: Export Datagrid from Database to Excel and Generate Chart[^]
 
Share this answer
 

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