复制代码 代码如下:
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;
}
}
}
}
相关推荐:
AI网页版本:开启智能时代的新篇章,拼音标调ai
优化公司:助力企业腾飞的秘密武器,微信营销推广价格多少
SEO自从上线后的演变与未来发展趋势,拼多多增加关键词排名
从“官网扒下来”看企业数字化转型的未来,摄影营销策略推广文案
好用的AI智能工具,让生活与工作更高效!
摘要AI生成:高效工作的新时代利器
为什么“未备案域名”会成为互联网行业中的重要问题?,江干区seo优化价格
AI撰写率:让创作变得更高效,助力内容产业腾飞,人力ai
SEO武汉:如何提升武汉地区网站的搜索引擎排名,景区网站建设费用
SEO要好,网站流量翻倍的关键秘诀,品牌网站建设关键词优化
SEO教你如何快速提升网站排名,打破竞争壁垒!,本溪seo优化排名公司
什么是seo伪原创,seo就业前景伪原创怎么写 ,头像ai画怎么弄
智能AI写作生成:如何借助人工智能提升创作效率与质量
文章AI指令提升写作效率的智能助手
自动写文章AI:高效创作工具,开启写作新纪元
ChatGPT页面怎么拖不动?解决问题的终极指南,日韩AI换脸在线观看
seo黑帽是什么,列举几种seo黑帽行为 ,穿老款的ai丢人吗
AI网页设计生成-智能化创造无限可能,ai机甲风背景音乐
SEO刷:让你的网站一夜之间登顶搜索引擎!,独特seo技巧
ChatGPT403:引领人工智能新时代,颠覆你的工作与生活方式,ai nak
用AI写文章查重率高吗?揭秘AI写作与查重检测的关系
SEO优化排名原理解析:如何提高网站排名,实现精准流量获取,奥迪ai售价
不利于seo是什么,不属于seo对网店推广的作用 ,ai渐变下载
SEO怎么做才能提升网站流量与排名?这篇文章给你全攻略,铁岭定制网站推广公司电话
SEO结构优化:助力网站提升排名与流量的关键策略,杭州小网站推广哪家好做
如何查文章AI率?全面解析AI文章检测工具及技巧
GPT-3.5免费吗?揭秘AI智能助手的未来与收费模式,ai 美美
ChatGPT诞生背景:人工智能如何突破语言的边界,ai辅助市场调研
seo用什么论坛引流,seo引流方法 ,ai写作续写神器
ChatGPT不能用了?了解这一背后的真相及解决方法,ai恐怖头像
ChatGPT最新版本更新内容:智能对话体验再升级,更多功能与应用,ai证伪
“新热度”:引领潮流的力量,如何趋势的脉搏,浙江通用网站建设特点
SEO定价策略:如何根据企业需求定制最佳价格方案,教育培训抖音营销推广
SEO教研:数字营销新趋势,提升网站流量与转化率的关键,齐鲁证券网站建设
怎么查一篇文章是不是AI写的?你需要这几个关键方法!
ChatGPT当前不可用?如何应对AI服务中断的挑战,ai文章免费写作app
互联网时代的“搜索截流”新玩法:如何抓住流量红利,甘孜做优化网站软件
SEO应该如何提升网站流量与排名?揭秘成功的SEO策略,肺炎疫苗推广营销
ChatGPT进不去怎么办?解决方案与技巧,轻松畅享智能对话,ai va
ChatGPT中显示已进行一处编辑,但看不到内容?你需要了解的隐藏问题!,ai敲
ChatGPT支持多种语言输入输出,让全球资讯触手可及,联想拯救者的ai写作
用AI写文,开启创作新时代
SEO赚钱:如何通过SEO技能在网络上实现财富自由,网站怎么建设推广平台
AI搜索写文章是什么意思?人工智能赋能内容创作的未来,高德地图 ai
为什么做seo的人很少,为了什么做seo ,ai不负你
AI免费生成文字,打造创作新时代
企业关键字-助力企业成功的隐形动力,闽侯县企业网站建设
SEO有点:揭秘优化之道,提升网站排名的秘诀,广州抖音seo厂家地址
文章创作AI:引领智能写作的新时代
AI做文章:引领智能创作的未来