Use ASP.net Gao chart (available for various voting procedures)
Compared with the ASP asp.net has more powerful features, the use of GDI + can easily achieve a lot of previously impossible graphics features.
First, build the library Mess.mdb in the C:\, and build the table title.
Build two fields, title (char), point (int type)
Very Satisfied 281
More Satisfied 297
It's 166.
Not satisfied with 416
I also wrote sections that draw lines and bars and are now writing them all into a class. Need to contact me: mailto:ouyang76@263.net
<%@ Page language= "C #"%>
<% @importNamespace= "System.Data"%>
<% @importNamespace= "System.Data.OleDb"%>
<% @importNamespace= "System.Drawing"%>
<% @importNamespace= "System.Drawing.Imaging"%>
<script language= "C #" runat= "Server" >
public void Page_Load (Object Obj,eventargs E)
{
Specify the connection string as a constant
Const String strconn = "provider=microsoft.jet.oledb.4.0;" +
"Data Source=c:\\mess.mdb";
OleDbConnection conn=new OleDbConnection (strconn);
Conn. Open ();
String Sql= "select * from title";
OleDbCommand cmd=new OleDbCommand (sql,conn);
DataSet ds=new DataSet ();
OleDbDataAdapter adapter1=new OleDbDataAdapter (cmd);
Adapter1. Fill (DS);
Conn. Close ();
float total=0.0f,tmp;
int iloop;
For (Iloop=0;iloop<ds. Tables[0]. rows.count;iloop++)
{
Tmp=convert.tosingle (ds. Tables[0]. rows[iloop]["point"]);//Convert to single precision, the vote can not be cast half-price. Can also be written as Convert.ToInt32
total+=tmp;
}
Response.Write (Convert.ToString (total));
Font fontlegend=new font ("Verdana", 9), fonttitle=new font ("Verdana", 10,fontstyle.bold);/Set Fonts
Fonttitle font for primary headers
int width=230;//white background width
const int bufferspace=15;
int Legendheight=fontlegend. Height* (ds. Tables[0]. rows.count+1) +bufferspace;
int titleheight = Fonttitle. Height + bufferspace;
int height = width + legendheight + titleheight + bufferspace;//white background high
int pieheight = width;
Rectangle pierect=new Rectangle (0,titleheight,width,pieheight);
Plus a variety of random colors
ArrayList colors = new ArrayList ();
Random rnd = new Random ();
for (iloop = 0; Iloop < ds. Tables[0]. Rows.Count; iloop++)
Colors. ADD (New SolidBrush (COLOR.FROMARGB) (Rnd. Next (255), Rnd. Next (255), Rnd. Next (255)));
Bitmap objbitmap=new Bitmap (width,height);//Create a Bitmap instance
//bitmap objbitmap=new Bitmap (230,500); Create a bitmap instance
Graphics objgraphics=graphics.fromimage (objbitmap);
Objgraphics. FillRectangle (New SolidBrush (Color.White), 0, 0, width, height);//Draw a white background
Objgraphics. FillRectangle (New SolidBrush (Color.lightyellow), pierect);//Draw a bright yellow background
The following is a Gao diagram (several rows of row paintings)
float currentdegree=0.0f;
for (iloop = 0; Iloop < ds. Tables[0]. Rows.Count; iloop++)
{
Objgraphics. FillPie ((SolidBrush) Colors[iloop], Pierect, Currentdegree,
Convert.tosingle (ds. Tables[0]. rows[iloop]["point"])/total * 360);
Currentdegree + = Convert.tosingle (ds. Tables[0]. rows[iloop]["point"])/total * 360;
}
---The following is the build main title
SolidBrush blackbrush=new SolidBrush (color.black);
String title= "The programmer base Camp" launched a matching special issue, are you satisfied with the special issue? ";
StringFormat StringFormat = new StringFormat ();
Stringformat.alignment = Stringalignment.center;
Stringformat.linealignment = Stringalignment.center;
Objgraphics. DrawString (title, Fonttitle, Blackbrush,
New Rectangle (0, 0, Width, titleheight), StringFormat);
List each field with the number of votes
Objgraphics. DrawRectangle (New Pen (Color.Black, 2), 0, height-legendheight, width, legendheight);
for (iloop = 0; Iloop < ds. Tables[0]. Rows.Count; iloop++)
{
Objgraphics. FillRectangle (SolidBrush) Colors[iloop], 5, Height-legendheight + fontlegend. Height * Iloop + 5, 10, 10);
Objgraphics. DrawString ((String) ds. Tables[0]. rows[iloop]["title"]) + "-" + convert.tostring (ds. Tables[0]. rows[iloop]["Point"]), Fontlegend, Blackbrush,
Height-legendheight + fontlegend. Height * iloop + 1);
}
//
Objgraphics. DrawString ("Total number of votes is:" +convert.tostring), Fontlegend,blackbrush, 5, Height-fontlegend. Height);
Total height of the image-the height of a line of fonts, that is, the height of one line of height-fontlegend for the bottom row. Height)
Response.contenttype= "Image/jpeg";
Objbitmap. Save (Response.outputstream,imageformat.jpeg);
Objbitmap. Save ("Myyyyyyyyyyy.jpg", imageformat.jpeg);//Output to File
Objgraphics. Dispose ();
Objbitmap. Dispose ();
}
</script>