Generate Chart Report in Windows Application
In this artcile i will explain how to generate chart report in Windows Application. Download and install chart addon from microsoft for .Net 3.5 then implement the chart and bind data to the windows application.
Generate Chart Report in Windows Application
Chart is not default addon so download chart addon for .Net Framework 3.5 from the following website http://www.microsoft.com/en-us/download/details.aspx?id=14422. First download chart exe from the website. Install MSChart.exe and default it will install in C:\Program Files\Microsoft Chart Controls. In your toolbox chart control will not be displayed. You have to manually add chart control by adding new tab name it as chart.add reference to System.Windows.Forms.DataVisualization.dll from the location C:\Program Files\Microsoft Chart Controls in toolbox under chart tab. Now chart conrol is displayed in the toolbox. Just drag the control into your windows application and adjust the size of the control.
Following is the code for binding data to chart control.
DataTable dt = new DataTable();
DataColumn dc;
dc = new DataColumn();
dc.ColumnName = "Name";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "Marks";
dt.Columns.Add(dc);
DataRow dr;
dr = dt.NewRow();
dr["Name"] = "Ravi";
dr["Marks"] = "54";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Rajesh";
dr["Marks"] = "66";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Ashok";
dr["Marks"] = "32";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Nirmal";
dr["Marks"] = "46";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Gopi";
dr["Marks"] = "26";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "David";
dr["Marks"] = "2";
dt.Rows.Add(dr);
chart1.Series["StudentMarks"].ChartType = SeriesChartType.Column;
chart1.DataSource = dt;
chart1.Series["StudentMarks"].XValueMember = "Name";
chart1.Series["StudentMarks"].YValueMembers = "Marks";
chart1.DataBind();
Final output of the sample chart application
I had attached sample chart application.