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
{
///
/// draw 的摘要说明。
///
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
cnt += num[i];
}
//flt = cnt /len;
for(i=0;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
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
}
//flt = cnt /len;
for(i=0;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
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);
}
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}