国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net畫曲線圖(折線圖)代碼 詳細注釋

2024-07-10 12:42:31
字體:
來源:轉載
供稿:網友
代碼如下:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//添加畫圖類
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;
using System.Data.SqlClient;
public partial class Curve_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Get_CurveData();
}
}
//獲取數據
public void Get_CurveData()
{
SqlConnection conn = null;
try
{
conn = CommonFunction.CreateDBTest();
conn.Open();
SqlCommand cmd = conn.CreateCommand();
string sqlStr = "SELECT * FROM CURVE ORDER BY TESTDATE";
DataTable dt = CommonFunction.ExecuteDatable(conn, cmd, CommandType.Text, sqlStr, null);
draw(dt);
}
catch (Exception exp)
{
Response.Write(exp.Message);
}
finally
{
if (conn != null)
conn.Close();
}
}
public void draw(DataTable dt)
{
//取得記錄數量
int count = dt.Rows.Count;
//記算圖表寬度
int wd = 80 + 20 * (count - 1);
//設置最小寬度為800
if (wd < 600) wd = 600;
//生成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);
//定義橫坐標間隔,(最佳值是總寬度-留空寬度[左右側都需要])/(記錄數量-1)
int xSpace = (wd - 100) / (count - 1);
//定義縱坐標間隔,不能隨便修改,跟高度和橫坐標線的條數有關,最佳值=(繪圖的高度-上面留空-下面留空)
int ySpace = 30;
//縱坐標最大值和間隔值
int yMaxValue = 30;
//繪制底色
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("測試曲線圖", Bfont, brush, 40, 5);
//繪制信息簡報
string info = " 曲線圖生成時間:" + DateTime.Now.ToString();
g.DrawString(info, Tfont, Bluebrush, 40, 25);
//繪制圖片邊框
g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 璧山县| 朝阳区| 祥云县| 阳新县| 叙永县| 赣州市| 潮州市| 闸北区| 宁夏| 高碑店市| 绥宁县| 长海县| 阿克苏市| 沙坪坝区| 金阳县| 天等县| 武平县| 呼图壁县| 天全县| 莆田市| 嫩江县| 阜康市| 上林县| 扎赉特旗| 西乌| 江都市| 广安市| 什邡市| 张家界市| 牙克石市| 陆河县| 古蔺县| 开原市| 高阳县| 金川县| 临朐县| 华宁县| 梁平县| 永城市| 东明县| 理塘县|