using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;
using System.Configuration;
using System.Web.UI.DataVisualization.Charting;
public partial class Graph_report : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
call2();
}
}
public void call2()
{
DataTable dt = new DataTable();
MySqlDataAdapter da;
using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["const"].ToString()))
{
string s = "select name,value as total from piechart order by total desc ";
MySqlCommand cmd = new MySqlCommand(s, con);
try
{
con.Open();
da = new MySqlDataAdapter(cmd);
da.Fill(dt);
con.Close();
string []x=new string[dt.Rows.Count];
int []y=new int[dt.Rows.Count];
for(int i=0;i<dt.Rows.Count;i++)
{
x[i]=dt.Rows[i][0].ToString();
y[i]= Convert.ToInt32(dt.Rows[i][1]);
}
Chart1.Series[0].Points.DataBindXY(x,y);
}
catch (Exception) { }
}
}
}
<div>
<asp:Chart ID="Chart1" runat="server">
<Series>
<asp:Series Name="Series1" ChartType="Pie" YValuesPerPoint="2"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1"></asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;
using System.Configuration;
using System.Web.UI.DataVisualization.Charting;
public partial class Graph_report : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
call2();
}
}
public void call2()
{
DataTable dt = new DataTable();
MySqlDataAdapter da;
using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["const"].ToString()))
{
string s = "select name,value as total from piechart order by total desc ";
MySqlCommand cmd = new MySqlCommand(s, con);
try
{
con.Open();
da = new MySqlDataAdapter(cmd);
da.Fill(dt);
con.Close();
string []x=new string[dt.Rows.Count];
int []y=new int[dt.Rows.Count];
for(int i=0;i<dt.Rows.Count;i++)
{
x[i]=dt.Rows[i][0].ToString();
y[i]= Convert.ToInt32(dt.Rows[i][1]);
}
Chart1.Series[0].Points.DataBindXY(x,y);
}
catch (Exception) { }
}
}
}
<div>
<asp:Chart ID="Chart1" runat="server">
<Series>
<asp:Series Name="Series1" ChartType="Pie" YValuesPerPoint="2"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1"></asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
No comments:
Post a Comment