How to Bind Data from DataBase to Pie Chart control in Windows using C#
In this article i am using a class which has database connection to refer it click here
Write a store procedure for binding and name it as "Student_Marks "
Form.CS Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace Pie_Charts_Sample
{
public partial class Form1 : Form
{
SqlHelper sql = new
SqlHelper();
public Form1()
{
InitializeComponent();
ShowPieChart();
}
private void
ShowPieChart()
{
Hashtable ht = new
Hashtable();
DataSet ds = sql.ExecuteProcudere("Student_Marks ", ht);
DataTable dt = ds.Tables[0];
PieChart.DataSource = dt;
PieChart.Series["Series1"].XValueMember
= "Name";
PieChart.Series["Series1"].YValueMembers
= "Percentage";
PieChart.DataBind();
}
}
}
OutPut :
No comments:
Post a Comment