代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
折线图
作者:
Dezai.CN
/ 发布于
2013/1/16
/
482
/// <summary> /// 绘制折线图 /// </summary> /// <param name="pnl">面板</param> /// <param name="lst">列表</param> publice void DrawZXT(Panel pnl, List<LineTest> lst) { float maxv = 0; foreach (LineTest item in lst) { foreach (LineTest subitem in item.test1) { if (subitem.Value > maxv) { maxv = subitem.Value; } } } string maxstr = maxv.ToString("0").Substring(0, 1); float mv = (float)(int.Parse(maxstr) + 1); while (mv < maxv) { mv *= 10; } maxv = mv; Graphics g = pnl.CreateGraphics(); g.FillRectangle(new SolidBrush(Color.FromArgb(255, pnl.ColorScheme.PanelBackground)), 1, 1, pnl.Width - 2, pnl.Height - 2); int xd = pnl.Width / 20; int yd = pnl.Height / 15; int[] ys = { yd * 13, yd * 12, yd * 11, yd * 10, yd * 9, yd * 8, yd * 7, yd * 6, yd * 5, yd * 4, yd * 3, yd * 2 }; int[] xs = { xd * 3, xd * 4, xd * 5, xd * 6, xd * 7, xd * 8, xd * 9, xd * 10, xd * 11, xd * 12, xd * 13, xd * 14, xd * 15, xd * 16 }; g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle er = new Rectangle(0, 0, pnl.Width, pnl.Height); Point lbPoint = new Point(xd * 17, yd * 2 + 6); Point lePoint = new Point(xd * 18 - 8, yd * 2 + 6); Point tPoint = new Point(xd * 18, yd * 2); // Random rand = new Random(); foreach (LineTest item in lst) { item.color = Color.FromArgb(rand.Next()); g.DrawLine(new Pen(item.color, 3), lbPoint, lePoint); g.FillEllipse(new SolidBrush(Color.FromArgb(255, item.color)), lePoint.X - 3, lePoint.Y - 3, 6, 6); g.DrawString(item.LblYear.ToString("0000") + "年", new Font("宋体", 10), Brushes.Black, tPoint); lbPoint.Y += 16; lePoint.Y += 16; tPoint.Y += 16; } g.DrawLine(new Pen(Color.Gray, 3), new Point(xs[0], ys[0]), new Point(xs[0], ys[ys.Length - 1])); g.DrawLine(new Pen(Color.Gray, 3), new Point(xs[0], ys[ys.Length - 1]), new Point(xs[0] - 5, ys[ys.Length - 1] + 5)); g.DrawLine(new Pen(Color.Gray, 3), new Point(xs[0], ys[ys.Length - 1]), new Point(xs[0] + 5, ys[ys.Length - 1] + 5)); g.DrawLine(new Pen(Color.Gray, 3), new Point(xs[0], ys[0]), new Point(xs[0] - yd, ys[0] + yd)); for (int i = 1; i < xs.Length - 1; i++) { g.DrawLine(new Pen(Color.LightGray, 1), new Point(xs[i], ys[0]), new Point(xs[i], ys[ys.Length - 1])); g.DrawString(string.Format("{0}月", i), new Font("宋体", 10), Brushes.Black, new Point(xs[i] - 12, ys[0] + 8)); } g.DrawLine(new Pen(Color.Gray, 3), new Point(xs[0], ys[0]), new Point(xs[xs.Length - 1], ys[0])); g.DrawLine(new Pen(Color.Gray, 3), new Point(xs[xs.Length - 1], ys[0]), new Point(xs[xs.Length - 1] - 5, ys[0] + 5)); g.DrawLine(new Pen(Color.Gray, 3), new Point(xs[xs.Length - 1], ys[0]), new Point(xs[xs.Length - 1] - 5, ys[0] - 5)); for (int j = 1; j < ys.Length - 1; j++) { g.DrawLine(new Pen(Color.LightGray, 1), new Point(xs[0], ys[j]), new Point(xs[xs.Length - 1], ys[j])); string s = string.Format("{0:N}", maxv / 10 * j); g.DrawString(s, new Font("宋体", 10), Brushes.Black, new Point(xs[0] - 10 - s.Length * 7, ys[j] - 8)); } for (int i = 0; i < lst.Count; i++) { for (int j = 0; j < lst[i].test1.Count; j++) { int yv = (int)((lst[i].test1[j].Value / maxv) * (ys[0] - ys[ys.Length - 2])); Point ap = new Point(xs[lst[i].test1[j].lblMonth], ys[0] - yv); Point bp; if (j == lst[i].test1.Count - 1) { bp = new Point(xs[0], ys[0]); } else { int yve = (int)((lst[i].test1[j + 1].Value / maxv) * (ys[0] - ys[ys.Length - 2])); bp = new Point(xs[lst[i].test1[j].lblMonth - 1], ys[0] - yve); } g.DrawLine(new Pen(lst[i].color, 3), ap, bp); g.FillEllipse(new SolidBrush(Color.FromArgb(255, lst[i].color)), ap.X-3,ap.Y-3,6,6); Point tP = new Point(); string sv = lst[i].test1[j].Value.ToString("0.00"); tP.X = ap.X-sv.Length/2 *7; tP.Y = ap.Y-16; g.DrawString(sv, new Font("宋体", 10), Brushes.Black, tP); } } } /// <summary> /// 折线图数据 /// </summary> public class LineTest { public LineTest(int y, int m, float v) { lblYear = y; lblMonth = m; Value = v; } public int lblYear { get; set; } public int lblMonth { get; set; } public float Value { get; set; } public Color color { get; set; } public List<LineTest> test1 = new List<LineTest>(); }
试试其它关键字
折线图
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3