日期:2011-10-08  浏览次数:20414 次

asp.net 绘制曲线图首先定义DrawClass类

 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;

/**//// <summary>
/// DrawClass 的摘要说明
/// </summary>
public class DrawClass
...{
    public DrawClass()
    ...{
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    public MemoryStream draw(DataSet ds, int Tnum)
    ...{
        //取得记录数量
        int count = ds.Tables[0].Rows.Count;
        //记算图表宽度
        int wd = 80 + 20 * (count - 1);
        //设置最小宽度为800
        if (wd < 800) wd = 800;
        //生成Bitmap对像
        Bitmap img = new Bitmap(wd, 400);
        //生成绘图对像
        Graphics g = Graphics.FromImage(img);
        //定义黑色画笔
        Pen Bp = new Pen(Color.Black);
        //定义红色画笔
        Pen Rp = new Pen(Color.Red);
        //定义银灰色画笔
        Pen Sp = new Pen(Color.Silver);
        //定义大标题字体
        Font Bfont = new Font("Arial", 12, FontStyle.Bold);
        //定义一般字体
        Font font = new Font("Arial", 6);
        //定义大点的字体
        Font Tfont = new Font("Arial", 9);
        //绘制底色
        g.DrawRectangle(new Pen(Color.White, 400), 0, 0, img.Width, img.Height);
        //定义黑色过渡型笔刷
        LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Black, Color.Black, 1.2F, true);
        //定义蓝色过渡型笔刷
        LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.Blue, 1.2F, true);
        //绘制大标题
        g.DrawString(ds.Tables[0].Rows[0]["sendid"].ToString() + "号订单发送情况曲线图", Bfont, brush, 40, 5);
        //取得当前发送量
        int nums = 0;
        for (int i = 0; i < count; i++)
        ...{
            nums += Convert.ToInt32(ds.Tables[0].Rows[i]["sendmum"]);
        }
        //绘制信息简报
        string info = "订单发送时间:" + ds.Tables[0