c#从dataGrid到Chart [英] c# from dataGrid to Chart
本文介绍了c#从dataGrid到Chart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,请帮帮我.我想从dataGrid表制作为Chart
这是我的dataGrid方法:
hello please help me. I want to make from dataGrid Table to Chart
this is my method for dataGrid :
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"];
}
我希望我的图表的X和Y分别具有"Sum(value)","name".
这是用于C#表单.
谢谢:)
I want my chart have "Sum(value)" , "name" for X , Y .
This is for C# Form.
Thanks :)
推荐答案
这里有一些很好的教程:
- http://www.dotnetperls.com/chart [ http://msdn.microsoft.com/en-us/library/dd489237.aspx [ ^ ]
- http://msdn.microsoft.com/en-us/library/dd489238.aspx [ ^ ]
请注意,该示例将静态值添加为点,这不是您想要的.您可以将数据表用作数据源 [ ^ ].
题外话:您不应将值直接串联到SQL语句中.这使您可以进行SLQ注入,数据类型转换问题等.相反,请使用 MySqlParameter [ ^ ]
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[^]
我想分享另一种方法,因为它使用了 free 数据导出组件来实现它:
查看详细信息:将数据网格从数据库导出到Excel并生成图表 [ ^ ]
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[^]
这篇关于c#从dataGrid到Chart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文