日期:2011-06-20 浏览次数:20469 次
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实例