asp.net+vml实现饼图制作


<%@ Import Namespace="System.Web " %>
<%@ Import Namespace="System.Web.Security " %>
<%@ Import Namespace="System.Data " %>
<%@ Import Namespace="System.Data.SqlClient " %>
<%@ Import Namespace="System.Data.OleDb " %>
<script language=javascript>
function show(pie){
pie.strokecolor=pie.fillcolor;
pie.strokeweight=2;
//div1.innerHTML=" " + pie.id +" " + pie.title + "";
}
function hide(pie){
pie.strokecolor="white";
pie.strokeweight=1;
//div1.innerHTML="";
}
function msg(pie){
// alert(pie.title);
}
</script>
<script language=C# runat="server">
?int tb_height=30;
?
?//画饼图/
?//传递参数:数据//
?
?public void DrawPie(DataSet ds,ArrayList colors,int table_x,int table_y,int all_width,int all_height)
? {???

???????? float total=0.0f,tmp;
???????? int iloop;
???????? for(iloop=0;iloop
??????? {
?????????????? tmp=Convert.ToInt32(ds.Tables[0].Rows[iloop][1]);
?????????????? total+=tmp;
??????? }
??float PreAngle=0.0f;
??//Response.Write(ds.Tables[0].Rows.Count);
??for(iloop=0;iloop
??{
?????????????? tt.InnerHtml += " ";

??PreAngle += Convert.ToSingle(ds.Tables[0].Rows[iloop][1])/total;
??// Response.Write(PreAngle);
??}

??????????????? Double pie=3.14159265358979;
??Double x3,x4;
??????????????? float TempPie=0.0f;
??????????????? for(iloop=0;iloop
??{
?????????????????? Double TempAngle=pie*2*(Convert.ToSingle(ds.Tables[0].Rows[iloop][1])/(total*2)+TempPie);
??//?? Response.Write(TempAngle+"
");
?????????????????? Double x1=table_x+all_width/2+Math.Cos(TempAngle)*all_width*3/8;
?????????????????? Double y1=table_y+all_height/2-Math.Sin(TempAngle)*all_height*3/8;
?????????????????? Double x2=table_x+all_width/2+Math.Cos(TempAngle)*all_width*3/4;
?????????????????? Double y2=table_y+all_height/2-Math.Sin(TempAngle)*all_height*3/4;
?????????????????? if(x2>table_x+all_width/2)
???? {
?????????????????????????? x3=x2;
?????????????????????????? x4=x3;
???? }
?????????????????? else{
?????????????????????????? x3=x2-20;
?????????????????????????? x4=x3-60;
???? }
??????????????? //?? Response.Write("x1="+x1+",y1="+y1+",x2="+x2+",y2="+y2+",x3="+x3+",x4="+x4+"
");
???? ss.InnerHtml += " ";
???? ss.InnerHtml += " ";
???? ss.InnerHtml += "

"+(Convert.ToSingle(ds.Tables[0].Rows[iloop][1])/total)*100+"% "+ds.Tables[0].Rows[iloop][0]+"
";
???? TempPie=TempPie+Convert.ToSingle(ds.Tables[0].Rows[iloop][1])/total;
???????????????? }
??//显示标住信息
??//ss.InnerHtml = " ";
??//for(iloop=0;iloop
??{
??// ss.InnerHtml += " ";
??????????????? // ss.InnerHtml += "
"+ds.Tables[0].Rows[iloop][0]+"
";

??????????????? // ss.InnerHtml += " ";

???????????????? //显示比例数
??????????????? // ss.InnerHtml += " ";

??????????????? // ss.InnerHtml += "

"+ds.Tables[0].Rows[iloop][1]+"
";
??}
? }

</script>

调用:










<script language=JavaScript src="../source/type.js" type=text/JavaScript></script>


<%@ Import Namespace="System " %>
<%@ Import Namespace="System.Web " %>
<%@ Import Namespace="System.Web.Security " %>
<%@ Import Namespace="System.Data " %>
<%@ Import Namespace="System.Data.SqlClient " %>
<%@ Import Namespace="System.Data.OleDb " %>
<%@ Register TagPrefix="WebReport" TagName="Chart" Src="../source/webreport.ascx"%>
<script language=C# runat="server">
public void Page_Load(Object sender,EventArgs e)
?{
????? if(!IsPostBack)
?? {
????? const String strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C://bak//test//GDI//Grades.mdb";
???????? OleDbConnection conn=new OleDbConnection(strconn);
???????? conn.Open();
???????? string sql="select month,temperature? from test where city='广州'";
???????? OleDbCommand cmd=new OleDbCommand(sql,conn);
???????? DataSet ds=new DataSet();
???????? OleDbDataAdapter adapter1=new OleDbDataAdapter(cmd);
???????? adapter1.Fill(ds);
?? int tbx,tby,allx,ally;
??????? // string sql1="select month,temperature from test where city='拉萨'";
?????? //? OleDbCommand cmd1=new OleDbCommand(sql1,conn);
?????? //? DataSet ds1=new DataSet();
?????? //? OleDbDataAdapter adapter2=new OleDbDataAdapter(cmd1);
?????? //? adapter2.Fill(ds1);
?? ArrayList colors = new ArrayList();
???????? colors.Add("#426baa");
?? colors.Add("#bcd48f");
?? colors.Add("#ff9900");
?? colors.Add("#bab6cb");
?? colors.Add("#666699");
?? colors.Add("#993300");
?? colors.Add("#fdd14a");
?? colors.Add("#e86bde");
?? colors.Add("#5ec06d");
?? colors.Add("#4970c6");
?? colors.Add("#ac6b3f");
?? colors.Add("#8676a5");
?? tbx=200;
?? tby=150;
?? allx=180;
?? ally=180;
?? if(Request.QueryString["id"]=="1")?? {
?? Pie.DrawPie(ds,colors,tbx,tby,allx,ally);
?? }
??}
?? }
?}

</script>




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值