欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c# 曲線圖生成代碼

 更新時(shí)間:2011年07月01日 00:28:50   作者:  
c# 曲線圖生成代碼,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:

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坐標(biāo)的標(biāo)題
/// </summary>
public string Xtitle
{
get { return xtitle; }
set { xtitle = value; }
}
/// <summary>
/// Y坐標(biāo)的標(biāo)題
/// </summary>
public string Ytitle
{
get { return ytitle; }
set { ytitle = value; }
}
/// <summary>
/// 副標(biāo)題
/// </summary>
public string Title2
{
get { return title2; }
set { title2 = value; }
}
/// <summary>
/// 主標(biāo)題
/// </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>
/// 創(chuàng)建并輸出圖片
/// </summary>
/// <returns>生成的文件路徑</returns>
public string Draw()
{
#region 基礎(chǔ)定義
//取得記錄數(shù)量
int count = itemlist.Count;

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

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

//繪制Y坐標(biāo)線
for (int i = 0; i < (count < 12 ? 12 : count); i++)
g.DrawLine(Sp, 40 + 50 * i, 60, 40 + 50 * i, 360);
//繪制X軸坐標(biāo)標(biāo)簽
for (int i = 0; i < count; i++)
g.DrawString(itemlist[i][0].ToString(), font, brush, 30 + 50 * i, 370);
//繪制X坐標(biāo)線
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坐標(biāo)值
g.DrawString(Math.Floor(s).ToString(), font, brush, 10, 55 + 30 * i);
}


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

#endregion

#region 繪制曲線
//定義曲線轉(zhuǎn)折點(diǎn)
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);
}
//繪制發(fā)送曲線
g.DrawLines(Rp, p);

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

#endregion

//繪制Y坐標(biāo)標(biāo)題
g.DrawString(ytitle, Tfont, brush, 10, 40);
//繪制X坐標(biāo)標(biāo)題
g.DrawString(xtitle, Tfont, brush, 30, 385);
//圖片質(zhì)量
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;
}

}
}
}

相關(guān)文章

  • C#實(shí)現(xiàn)雙端隊(duì)列的示例代碼

    C#實(shí)現(xiàn)雙端隊(duì)列的示例代碼

    雙端隊(duì)列是一種可以在兩端擴(kuò)展或收縮的序列化容器,本文主要介紹了C#實(shí)現(xiàn)雙端隊(duì)列的示例代碼,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-11-11
  • C#實(shí)現(xiàn)去除Strings中空格的方法

    C#實(shí)現(xiàn)去除Strings中空格的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)去除Strings中空格的方法,較為詳細(xì)的介紹了C#實(shí)現(xiàn)去除字符串首尾及中間空格的方法,是非常實(shí)用的技巧,需要的朋友可以參考下
    2014-10-10
  • c# RSA非對(duì)稱加解密及XML&PEM格式互換方案

    c# RSA非對(duì)稱加解密及XML&PEM格式互換方案

    這篇文章主要介紹了c# RSA非對(duì)稱加解密及XML&PEM格式互換方案,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-12-12
  • C#很簡(jiǎn)單而又很經(jīng)典的一句代碼實(shí)例

    C#很簡(jiǎn)單而又很經(jīng)典的一句代碼實(shí)例

    這篇文章主要給大家分享介紹了關(guān)于C#很簡(jiǎn)單而又很經(jīng)典的一句代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用C#具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • 人臉認(rèn)證源碼faceIdentify詳解

    人臉認(rèn)證源碼faceIdentify詳解

    這篇文章主要為大家詳細(xì)介紹了人臉認(rèn)證源碼faceIdentify的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • C#遞歸算法之快速排序

    C#遞歸算法之快速排序

    快速排序由C.A.R發(fā)明,它依據(jù)中心元素的值,利用一系列遞歸調(diào)用將數(shù)據(jù)表劃分成越來(lái)越小的子表。在每一步調(diào)用中,經(jīng)過(guò)多次的交換,最終為中心元素找到最終的位置。
    2016-06-06
  • C#操作注冊(cè)表的方法

    C#操作注冊(cè)表的方法

    以下從‘讀’‘寫(xiě)’‘刪除’‘判斷’四個(gè)事例實(shí)現(xiàn)對(duì)注冊(cè)表的簡(jiǎn)單操作
    2007-03-03
  • C#導(dǎo)出GridView數(shù)據(jù)到Excel文件類實(shí)例

    C#導(dǎo)出GridView數(shù)據(jù)到Excel文件類實(shí)例

    這篇文章主要介紹了C#導(dǎo)出GridView數(shù)據(jù)到Excel文件類,實(shí)例分析了C#使用GridView及Excel的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03
  • Unity實(shí)現(xiàn)首字母檢索器

    Unity實(shí)現(xiàn)首字母檢索器

    這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)首字母檢索器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • C#如何創(chuàng)建自定義特性

    C#如何創(chuàng)建自定義特性

    這篇文章主要介紹了C#如何創(chuàng)建自定義特性,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-04-04

最新評(píng)論