日期:2011-09-16 浏览次数:20437 次
前段时间项目需要,写了一个简单的图标统计类.决定以后写点东西到Blog来.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
namespace CrystalReportsDemo
...{
/**//// <summary>
/// createReport绘制图形报表-柱图。
/// </summary>
public class createReport
...{
public createReport()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
public Bitmap CreatePictureReport(string[] x,int[] y,string ReportName)
...{
if(x.Length != y.Length)
...{
throw new Exception("X和Y数目不一致");
}
int colNum=y.Length;
int colScale=880/(colNum+1);
Bitmap bmp = new Bitmap(900,700,PixelFormat.Format24bppRgb);
Graphics dc = Graphics.FromImage(bmp);
dc.FillRectangle(new SolidBrush(Color.White),0,0,900,700);
Pen scalePen = new Pen(Color.Black,2);
Pen gridPen = new Pen(Color.Black,1);
dc.DrawLine(scalePen,20,680,880,680);
dc.DrawLine(scalePen,20,680,20,20);
dc.DrawLine(gridPen,20,20,880,20);
dc.DrawLine(gridPen,880,20,880,680);
Point drawPoint;
int XPoint;
int YHeight;
if(colNum==0)
...{
throw new Exception("无数据值,colNum值为0作为除数,抛出异常");
}
int drawWidth=880/(4*colNum);
//int drawWidth=580/(4*colNum+1);//4*colNum+1 确保colNum不为0.否则580/(4*0);的话会异常.0不能作为除数
int maxNum=getMaxNum(y);
Rectangle rct;
Random