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
}
}
新闻热点
疑难解答