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>
/// draw 的摘要說明。
/// </summary>
public class draw : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
Draw_Imgbar();
}
//畫棒圖
void Draw_Imgbar(){
//創建一個長度為400,寬帶為400的Bitmap實例
Bitmap bmp = new Bitmap(400,300);
Graphics g;
g = Graphics.FromImage(bmp);
g.Clear(Color.Snow);
string[] sitem = {"很好","好","一般","差"};
int[] num = {1000,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 = "調查統計結果一覽圖";
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 ) ;
//繪制小方塊
g.FillRectangle ( new SolidBrush( Return_Color( i ) ) , myRec.X , myRec.Y , 20 , 10 ) ;
//填充小方塊
g.DrawString ( " " + sitem[i], new Font( "宋體" , 9 ) , Brushes.Black , myDec ) ;
//繪制小方塊右邊的文字
myRec.Y += 15 ;
myDec.Y += 15 ;
g . DrawRectangle ( Pens.Black , ( i * iBarWidth ) + 15 , 290 - (nflt[ i ] * scale ) , 20 , ( nflt[ i ] * scale ) + 5 ) ;
//繪制Bar圖
g . FillRectangle ( new SolidBrush ( Return_Color( i ) ) , ( i * iBarWidth ) + 15 , 290 - ( nflt[ i ] * scale ) , 20 , ( nflt[ i ] * scale ) + 5 ) ;
//以指定的色彩填充Bar圖
g . DrawString ( num[ i ].ToString ( ) , new Font( "宋體" , 9 ) , Brushes.Black , ( i * iBarWidth ) + 20 , 275 - (nflt[ i ] * scale ) ) ;
//顯示Bar圖代表的數據
//s = s + nflt[i];
}
Pen p = new Pen ( Color.Black , 1 ) ;
g . DrawRectangle ( p , 1 , 1 , 398 , 298 ) ;
bmp.Save ( Response.OutputStream , System.Drawing.Imaging.ImageFormat.Jpeg);
bmp.Dispose();
}
//畫餅圖
void Draw_Img(){
Bitmap bmp = new Bitmap(400,300);
//創建一個長度為400,寬帶為400的Bitmap實例
Graphics g;
g = Graphics.FromImage(bmp);
g.Clear(Color.Snow);
string[] sitem = {"很好","好","一般","差"};
int[] num = {1000,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 = "調查統計結果一覽圖";
g.DrawString ( header , new Font( "宋體", 12,FontStyle.Bold) , Brushes.Black , new Point( 75 , 10 ) ) ;
g.DrawString ( "單位:次" , 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 ) ;
//繪制小方塊
g.FillRectangle ( new SolidBrush( Return_Color( i ) ) , myRec.X , myRec.Y , 20 , 10 ) ;
//填充小方塊
g.DrawString ( " " + sitem[i] + " " + num[i], new Font( "宋體" , 9 ) , Brushes.Black , myDec ) ;
//繪制小方塊右邊的文字
myRec.Y += 15 ;
myDec.Y += 15 ;
g.FillPIE( new SolidBrush (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 . DrawRectangle ( 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;
}
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.Net Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}