C# Chart Control Tutorial In Urdu - Create Chart With Multiple Columns/Series
Code here
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace ComplexChartVC4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
//chart1.DataSource = GetData();
//chart1.Series["Series1"].XValueMember = "Registration Type";
//chart1.Series["Series1"].YValueMembers = "Total";
chart1.DataBindCrossTable(GetData().DefaultView, "Registration Type", "Year", "Total", "Label=Total");
}
private DataTable GetData()
{
DataTable dtChartData = new DataTable();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbx"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("usp_ChartData3", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
dtChartData.Load(reader);
}
}
return dtChartData;
}
}
}
Stored Procedure: usp_ChartData3
CREATE PROCEDURE [dbo].[usp_ChartData3]
AS
BEGIN
SELECT COUNT(st.StudentId) AS 'Total'
,ld.Description AS 'Registration Type'
,DATEPART(yyyy, st.DateOfRegistration) AS 'Year'
FROM dbo.Students st
INNER JOIN dbo.ListData ld ON st.RegistrationType = ld.LisDataId
GROUP BY DATEPART(yyyy, st.DateOfRegistration), ld.Description
END
No comments:
Post a Comment