-
C#教程之C#实现绘制面形图表的方法详解
本例详细讲述了C#实现的面形图绘制例子,这是其中一个核心绘制文件的代码,代码中的里面的注释很多,也比较详细,相信对于初学者学习及理解C#图形绘制方面的技术要点、难点有所帮助。
C#绘制面形图的主要功能代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace 绘制面形图 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Graphics g; //创建Graphics对象 private void button1_Click( object sender, EventArgs e) { Bitmap bt = new Bitmap(panel1.Width, panel1.Height); //实例化一个Bitmap对象 int flag = (panel1.Width-4 )/ 6; //X轴的增值 g = Graphics.FromImage(bt); //实例化Graphics对象 Pen p = new Pen(Color.Black, 1); //设置Pen对象 g.DrawLine(p, new Point(0, 0), new Point(0, panel1.Height-20)); //绘制Y轴 g.DrawLine(p, new Point(0, panel1.Height - 20), new Point(panel1.Width - 4, panel1.Height - 20)); //绘制X轴 //声明一个用于绘制颜色的数组 Color[] cl = new Color[] { Color.Red, Color.Blue, Color.YellowGreen, Color.Yellow, Color.RoyalBlue, Color.Violet, Color .Tomato}; int [] points = { 20,70,80,60,40,100,10}; //声明一个计算走势峰值的数组 Point pt1 = new Point(0, panel1.Height - 20 - points[0]); //记录绘制四边形的第一个点 Point pt2 = new Point(0, panel1.Height - 20); //记录绘制四边形的第二个点 for ( int i = 0; i <= 6; i++) //通过for循环绘制月份和面形图 { PointF p1 = new PointF(flag * i, panel1.Height - 20); //计算每个月份数字的坐标 //绘制显示月份的数字 g.DrawString(i.ToString(), new Font( "宋体" , 9), new SolidBrush(Color.Black), new PointF(p1.X - 2, p1.Y)); //记录绘制四边形的第三个点 Point pt3 = new Point(flag * i, panel1.Height - 20); //记录绘制四边形的第四个点 Point pt4 = new Point(flag * i, panel1.Height - 20 - points[i]); Point[] pt={pt1,pt2,pt3,pt4}; //声明一个Point数组 g.FillPolygon( new SolidBrush(cl[i]), pt); //填充四边形的颜色 //当继续绘制下一个四边形时,前一个四边形的最后两个点作为下一个四边形的起始点 pt1 = pt4; pt2 = pt3; } panel1.BackgroundImage = bt; //显示绘制的面形图 } private void Form1_Load( object sender, EventArgs e) { } } } |
面形图是平时很普及的一种图表风格,用来显示数据挺方便的。合理的加以应用相信会对程序数据展现的视觉效果有很大的提高!
栏目列表
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比