麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > C# > 正文

c# 曲線圖生成代碼

2020-01-24 03:43:05
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;
using System.Collections;

namespace Curve
{
public class CurveDrawing
{
string title, title2, ytitle, xtitle;
/// <summary>
/// X坐標的標題
/// </summary>
public string Xtitle
{
get { return xtitle; }
set { xtitle = value; }
}
/// <summary>
/// Y坐標的標題
/// </summary>
public string Ytitle
{
get { return ytitle; }
set { ytitle = value; }
}
/// <summary>
/// 副標題
/// </summary>
public string Title2
{
get { return title2; }
set { title2 = value; }
}
/// <summary>
/// 主標題
/// </summary>
public string Title
{
get { return title; }
set { title = value; }
}
double yMax, yMin;
List<ArrayList> itemlist;

public CurveDrawing(List<ArrayList> itemlist, string title, string title2 = "")
{
this.itemlist = itemlist;
this.title = title;
this.title2 = title2;

yMax = -100000000;
yMin = 100000000;
for (int i = 0; i < itemlist.Count; i++)
{
if (Convert.ToDouble(itemlist[i][1]) > yMax)
yMax = Convert.ToDouble(itemlist[i][1]);
if (Convert.ToDouble(itemlist[i][1]) < yMin)
yMin = Convert.ToDouble(itemlist[i][1]);
}
}
/// <summary>
/// 創建并輸出圖片
/// </summary>
/// <returns>生成的文件路徑</returns>
public string Draw()
{
#region 基礎定義
//取得記錄數量
int count = itemlist.Count;

//記算圖表寬度
int wd = 80 + 50 * (count - 1);
//設置最小寬度為640
if (wd < 640) wd = 640;
//生成Bitmap對像
Bitmap img = new Bitmap(wd, 400);
//定義黑色畫筆
Pen Bp = new Pen(Color.Black);
//加粗的黑色
Pen BBp = new Pen(Color.Black, 2);
//定義紅色畫筆
Pen Rp = new Pen(Color.Red);
//定義銀灰色畫筆
Pen Sp = new Pen(Color.Silver);
//定義大標題字體
Font Bfont = new Font("黑體", 12, FontStyle.Bold);
//定義一般字體
Font font = new Font("Arial", 8);
//定義大點的字體
Font Tfont = new Font("Arial", 9);
//定義黑色過渡型筆刷
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);
LinearGradientBrush Silverbrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Silver, Color.Silver, 1.2F, true);
#endregion

//生成繪圖對像
try
{
using (Graphics g = Graphics.FromImage(img))
{
#region 繪制圖表
//繪制底色
g.DrawRectangle(new Pen(Color.White, 400), 0, 0, img.Width, img.Height);
//繪制大標題
g.DrawString(title, Bfont, brush, wd / 2 - title.Length * 10, 5);
//繪制小標題
g.DrawString(title2, Tfont, Silverbrush, wd / 2 - title.Length * 10 + 40, 25);
//繪制圖片邊框
g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);

//繪制Y坐標線
for (int i = 0; i < (count < 12 ? 12 : count); i++)
g.DrawLine(Sp, 40 + 50 * i, 60, 40 + 50 * i, 360);
//繪制X軸坐標標簽
for (int i = 0; i < count; i++)
g.DrawString(itemlist[i][0].ToString(), font, brush, 30 + 50 * i, 370);
//繪制X坐標線
for (int i = 0; i < 11; i++)
{
g.DrawLine(Sp, 40, 60 + 30 * i, 40 + 50 * ((count < 12 ? 12 : count) - 1), 60 + 30 * i);
double s = yMax - (yMax + Math.Abs(yMin)) / 10 * i;//最大的Y坐標值
g.DrawString(Math.Floor(s).ToString(), font, brush, 10, 55 + 30 * i);
}


//繪制Y坐標軸
g.DrawLine(BBp, 40, 50, 40, 360);
//繪制X坐標軸
g.DrawLine(BBp, 40, 360, 40 + 50 * ((count < 12 ? 12 : count) - 1) + 10, 360);

#endregion

#region 繪制曲線
//定義曲線轉折點
Point[] p = new Point[count];
for (int i = 0; i < count; i++)
{
p[i].X = 40 + 50 * i;
p[i].Y = 360 - (int)(((Convert.ToDouble(itemlist[i][1]) + Math.Abs(yMin)) / ((yMax + Math.Abs(yMin)) / 10)) * 30);
}
//繪制發送曲線
g.DrawLines(Rp, p);

for (int i = 0; i < count; i++)
{
//繪制發送記錄點的數值
g.DrawString(itemlist[i][1].ToString(), font, Bluebrush, p[i].X + 5, p[i].Y - 10);
//繪制發送記錄點
g.DrawRectangle(Rp, p[i].X - 2, p[i].Y - 2, 4, 4);
}

#endregion

//繪制Y坐標標題
g.DrawString(ytitle, Tfont, brush, 10, 40);
//繪制X坐標標題
g.DrawString(xtitle, Tfont, brush, 30, 385);
//圖片質量
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//保存繪制的圖片
string basePath = HttpContext.Current.Server.MapPath("/Curve/"),
fileName = Guid.NewGuid() + ".jpg";

using (FileStream fs = new FileStream(basePath + fileName, FileMode.CreateNew))
{
if (!System.IO.Directory.Exists(basePath))
System.IO.Directory.CreateDirectory(basePath);
img.Save(fs, ImageFormat.Jpeg);
return "/Curve/" + fileName;
}
}

}
catch (Exception)
{
throw;
}

}
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 九九看片 | 最新中文字幕第一页视频 | 97干在线 | 黄污网站在线观看 | 热99在线 | 久久精品视频一区二区 | 久草热久| fc2成人免费人成在线观看播放 | 黄色网址在线免费播放 | 姑娘第四集免费看视频 | www成人在线观看 | a级毛片免费观看在线播放 日本aaa一级片 | 一区二区三区欧美在线观看 | 精品国产乱码久久久久久丨区2区 | aa久久| 在线 日本 制服 中文 欧美 | 国产成人强伦免费视频网站 | arabxxxxvideos| 久久久久久久久日本理论电影 | 久久国产精品99国产 | jizzjizzjizz少妇| 在线日韩av电影 | 久久欧美亚洲另类专区91大神 | 中文欧美日韩 | 亚洲第一色婷婷 | 欧美视频一区二区 | 91视频久久| 欧美黄色大片免费观看 | 九九视频精品在线 | 欧美爱爱一区二区 | 欧美在线成人影院 | 国产成人在线免费观看视频 | 国产精品视频1区 | 男女做性免费网站 | 国产亚洲精品久久久久婷婷瑜伽 | 国产亚洲精彩视频 | 桥本有菜免费av一区二区三区 | 一级α片免费看刺激高潮视频 | av电影直播 | 91午夜在线观看 | 欧美不卡 |