Address: http://blog.csdn.net/asthlon/archive/2004/11/22/190965.aspx
Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Namespace xcrm. Module. Report
{
/// <Summary>
/// Abstract of draw.
/// </Summary>
Public class draw: system. Web. UI. Page
{
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
Draw_imgbar ();
}
// Draw a bar chart
Void draw_imgbar (){
// Create a bitmap instance with a length of 400 and a bandwidth of 400
Bitmap BMP = new Bitmap (400,300 );
Graphics g;
G = graphics. fromimage (BMP );
G. Clear (color. Snow );
String [] sitem = {"good", "good", "General", "poor "};
Int [] num = {, 69, 90,2000 };
Int CNT, I, Len, ibarwidth;
Float scale;
Float [] nflt;
String header;
Header = "";
CNT = 0;
Ibarwidth = 40;
Scale = 1;
Len = num. length;
// Nflt. Length = Len;
Nflt = new float [Len];
For (I = 0; I <Len; I ++)
{
CNT + = num [I];
}
// FLT = CNT/Len;
For (I = 0; I <Len; I ++)
{
Nflt [I] = 200 * num [I]/CNT;
// Nflt [I] = scale * num [I]/CNT;
}
Header = "survey statistical result overview ";
G. drawstring (header, new font ("", 12, fontstyle. Bold), brushes. Black, new point (75, 10 ));
Point myrec = new point (300, 40 );
Point mydec = new point (320, 40 );
For (I = 0; I <Len; I ++)
{
G. drawrectangle (pens. Black, myrec. X, myrec. Y, 20, 10 );
// Draw small blocks
G. fillrectangle (New solidbrush (return_color (I), myrec. X, myrec. Y, 20, 10 );
// Fill the small square
G. drawstring ("" + sitem [I], new font ("", 9), brushes. Black, mydec );
// Draw the text on the right of the small square
Myrec. Y + = 15;
Mydec. Y + = 15;
G. drawrectangle (pens. Black, (I * ibarwidth) + 15,290-(nflt [I] * scale), 20, (nflt [I] * scale) + 5 );
// Draw a bar chart
G. fillrectangle (New solidbrush (return_color (I), (I * ibarwidth) + 15,290-(nflt [I] * scale), 20, (nflt [I] * scale) + 5 );
// Fill the bar chart with the specified color
G. drawstring (Num [I]. tostring (), new font ("", 9), brushes. black, (I * ibarwidth) + 20,275-(nflt [I] * scale ));
// Display the data represented by the bar chart
// S = S + nflt [I];
}
Pen P = new pen (color. Black, 1 );
G. Fig (P, 1, 1,398,298 );
BMP. Save (response. outputstream, system. Drawing. imaging. imageformat. JPEG );
BMP. Dispose ();
}
// Pie chart
Void draw_img (){
Bitmap BMP = new Bitmap (400,300 );
// Create a bitmap instance with a length of 400 and a bandwidth of 400
Graphics g;
G = graphics. fromimage (BMP );
G. Clear (color. Snow );
String [] sitem = {"good", "good", "General", "poor "};
Int [] num = {, 69, 90, 20 };
Int CNT, I, Len;
Float S;
Float [] nflt;
String header;
Header = "";
CNT = 0;
S = 0;
Len = num. length;
// Nflt. Length = Len;
Nflt = new float [Len];
For (I = 0; I <Len; I ++ ){
CNT + = num [I];
}
// FLT = CNT/Len;
For (I = 0; I <Len; I ++ ){
Nflt [I] = 360 * num [I]/CNT;
}
Header = "survey statistical result overview ";
G. drawstring (header, new font ("", 12, fontstyle. Bold), brushes. Black, new point (75, 10 ));
G. drawstring ("unit: Times", new font ("", 9), brushes. Black, new point (300, 25 ));
Point myrec = new point (300, 40 );
Point mydec = new point (320, 40 );
For (I = 0; I <Len; I ++)
{
If (I = len-1 ){
// S = 360-s;
Nflt [I] = 360-s;
}
G. drawrectangle (pens. Black, myrec. X, myrec. Y, 20, 10 );
// Draw small blocks
G. fillrectangle (New solidbrush (return_color (I), myrec. X, myrec. Y, 20, 10 );
// Fill the small square
G. drawstring ("" + sitem [I] + "" + num [I], new font ("", 9), brushes. Black, mydec );
// Draw the text on the right of the small square
Myrec. Y + = 15;
Mydec. Y + = 15;
G. fillpie (New SolidWorks (return_color (I), 50, 50,200,200, S, nflt [I]);
G. drawpie (pens. Black, 50, 50,200,200, S, nflt [I]);
S = S + nflt [I];
}
Pen P = new pen (color. Black, 1 );
G. Fig (P, 1, 1,398,298 );
BMP. Save (response. outputstream, system. Drawing. imaging. imageformat. JPEG );
}
Public color return_color (int I ){
Switch (I ){
Case 0:
Return color. Red;
// Break;
Case 1:
Return color. blue;
// Break;
Case 2:
Return color. Yellow;
Case 3:
Return color. Green;
// Break;
Case 4:
Return color. Pink;
// Break;
Case 5:
Return color. PLUM;
// Break;
Case 6:
Return color. Gray;
// Break;
Case 7:
Return color. Salmon;
// Break;
Case 8:
Return color. rosybrown;
// Break;
Case 9:
Return color. Teal;
// Break;
Case 10:
Return color. Orange;
// Break;
Case 11:
Return color. thistle;
// Break;
Case 12:
Return color. Maroon;
// Break;
Default:
Return color. whitesmoke;
// Break;
}
}
# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );
}
# Endregion
}
}