程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> asp.net生成曲線圖的過程

asp.net生成曲線圖的過程

編輯:.NET實例教程

這裡是從Dataset裡的數據生成曲線圖.

我的Dataset是從表Sendrec裡讀取的數據,分別有Id,Sendid(訂單號),Sendtime(記錄時間),Sendnum(單位時間發送量/我這裡是五分鐘)幾個字段

過程如下:

public void draw(Page page,DataSet ds,int Tnum){}
其中page是用來傳遞引用這個過程的頁面,這樣讓頁面是JPG方式直接向客戶端輸出生成的曲線圖.
ds就是取出來的數據集了

Tnum只是我這裡要用到的一個參數,不想讓這個類去接觸讀取過程,所以把訂單的總量直接取出後傳遞給它的.
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.HtmlControls;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;


public class imgdraw
{
public imgdraw()
{

}
public void draw(Page page,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]["sendnum"]);
}
//繪制信息簡報
string info="訂單發送時間:"+ds.Tables[0].Rows[0]["sendtime"].ToStrin

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved