Hi @RAVI,
Unfortunately, ASP.NET 2.0 has been unsupported. detail:ASP.NET Support Policy
I think you'd better migrate your project to the latest version.
How to: Configure an App to Support .NET Framework 4 or later versions
It's best to create a new project with the latest version, as a lot of issues can arise with the migration.
Then use the following code.
You can use the ASP.Net Chart control to achieve the results you want.
Below is an example of a donut chart based on your data.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="NewDemoWebForm.WebForm4" %>
<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Chart ID="Chart1" runat="server">
<Legends>
<asp:Legend Alignment="Center" Docking="Bottom" Name="Default"
LegendStyle="Row" />
</Legends>
<Series>
<asp:Series Name="Default" ></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1" ></asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
//get connection string from web config
string constr = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
//query to fetch Employee Salary and getting Count of each salary in table, the group by with Emp Salary
using (SqlCommand cmd = new SqlCommand("SELECT name,value FROM Table_1 "))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable ChartData = ds.Tables[0];
//storing total rows count to loop on each Record
string[] XPoints = new string[ChartData.Rows.Count];
int[] YPOints = new int[ChartData.Rows.Count];
for (int count = 0; count < ChartData.Rows.Count; count++)
{
// store values for X axis
XPoints[count] = ChartData.Rows[count]["name"].ToString();
//store values for Y Axis
YPOints[count] = Convert.ToInt32(ChartData.Rows[count]["value"]);
}
//binding chart control
Chart1.Series[0].Points.DataBindXY(XPoints, YPOints);
Chart1.Series[0].Label = "#PERCENT{P0}";
Chart1.Series[0].BorderWidth = 2;
Chart1.Series[0].BorderColor = Color.White;
//setting Chart type
Chart1.Series[0].ChartType = SeriesChartType.Doughnut;
//enable to show legend
Chart1.Series[0].LegendText = "#VALX";
Chart1.Legends[0].Enabled = true;
//show chart in 3d
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
}
}
}
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.