图表不是我想像中的那样,比率画不出来,提取数据有也有点问题
using System;using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Reflection;
public partial class _Default : System.Web.UI.Page
{
string[] Mon = new string[12];
int[] Number = new int[12];
private void getInfo()
{
string myConnectionString = "server=B11BF8375873411SQLEXPRESS;DataBase=months;uid=sa;pwd=456000;";
SqlConnection myconnection = new SqlConnection(myConnectionString);
string cmdString = "select mon,number from month order by mon ";
myconnection.Open();
SqlCommand mycommand = new SqlCommand(cmdString, myconnection);
SqlDataReader myReader = mycommand.ExecuteReader();
int index = 0;
while (myReader.Read())
{
Mon[index] = Convert.ToString (myReader.GetSqlInt32(0))+"月" ;
Number[index] = (int)myReader.GetSqlInt32(1);
}
myconnection.Close();
}
private Color GetColor(int i)
{
Color myColor;
switch (i)
{
case 0:
myColor = Color.Cornsilk;
return myColor;
case 1:
myColor = Color.Red;
return myColor;
case 2:
myColor = Color.Yellow ;
return myColor;
case 3:
myColor = Color.Peru;
return myColor;
case 4:
myColor = Color.AliceBlue ;
return myColor;
case 5:
myColor = Color.Bisque ;
return myColor;
case 6:
myColor = Color.Gray ;
return myColor;
case 7:
myColor = Color.Maroon ;
return myColor;
case 8:
myColor = Color.Azure ;
return myColor;
case 9:
myColor = Color.Orange ;
return myColor;
case 10:
myColor = Color.Coral ;
return myColor;
case 11:
myColor = Color.BurlyWood ;
return myColor;
default :
myColor = Color.Green;
return myColor;
}
}
private void CarryOutPic()
{
Bitmap myImage = new Bitmap(600, 300);
Graphics myG = Graphics.FromImage(myImage);
myG.Clear(Color.White);
myG.DrawString("XX公司XX产品2007年销售情况一看表", new System.Drawing.Font("宋体",15), Brushes.Black, new Point(5, 5));
Point myRec = new Point(515, 30);
Point myDec = new Point(540, 30);
Point myTxt = new Point(565, 30);
myG.DrawString("单位:万件", new Font("宋体",9), Brushes.Black, new Point(512, 12));
for (int i = 0; i < Mon.Length; i++)
{
myG.FillRectangle(new SolidBrush(GetColor(i)), myRec.X, myRec.Y, 20, 10);
myG.DrawRectangle(Pens.Black, myRec.X, myRec.Y, 20, 10);
myG.DrawString(Convert.ToString(Mon[i]), new Font("宋体", 9), Brushes.Black, myDec);
myG.DrawString(Convert.ToString(Number[i]), new Font("宋体", 9), Brushes.Black, myTxt);
myRec.Y += 15;
myDec.Y += 15;
myTxt.Y += 15;
}
int Total = 0;
float CurrentAngle = 0;
float StartAngle = 0;
for (int i = 0; i < Number.Length; i++)
{
Total += Number[i];
}
for (int i = 0; i < Number.Length; i++)
{
if (i == Number.Length - 1)
{
CurrentAngle = 360 - StartAngle;
}
else
{
int Temple=Number[i];
StartAngle =(Temple*360)/Total ;
}
myG.DrawPie(Pens.Black ,100,40,250,250,StartAngle ,CurrentAngle );
myG.FillPie (new SolidBrush(GetColor (i)),100,40,250,250,StartAngle ,CurrentAngle );
StartAngle +=CurrentAngle ;
}
Pen myPen=new Pen(Color.Black ,2);
myG.DrawRectangle (myPen ,1,1,598,298);
myImage.Save (Response .OutputStream,System.Drawing .Imaging .ImageFormat .Gif );
myImage .Dispose();
myG.Dispose ();
myPen.Dispose ();
}
protected void Page_Load(object sender, EventArgs e)
{
getInfo();
CarryOutPic();
}
}
--------------------编程问答-------------------- flex+.net 画图很舒服
补充:.NET技术 , ASP.NET