惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - Phoenix

Server Explorer disappeared in VS 2008 如何在外部得到一个event是否已被注册 FlashGet的堕落 SQL2000自动备份数据库到远程机器 Vista: user does not have administrative privileges in command prompt mode. 将一个域中的MS CRM数据库部署到另外一个域中 求救手工设置笔记本IRQ的方法 用纯API写的窗体 Windows下安装SQLPlus的帮助 Oracle Listener报“TNSLSNR.exe 应用程序错误” 正则表达式超时 [导入]不使用COM组件弹出数据库连接对话框 [导入]C#: 通过动态编译获取字符串所表达的值 [导入]Asp.Net中连接Oracle [导入]全角字符的匹配 [导入]使用.Net获取OLEDB数据库的架构. [导入]使用C#在进度条中显示复制文件的进度 [导入]在SQL Server2000中修改系统表 [导入]已经毕业3个月了,怀念大学生活啊。。。
画一个立体的柱图 - Phoenix - 博客园
Phoenix · 2007-02-15 · via 博客园 - Phoenix

画立体柱图应该非常的简单,就是两个截面+柱体。所以我就不做多的描述了,请直接看代码吧:

 1/// <summary>
 2    /// Draw Bar Chart
 3    /// </summary>
 4    /// <param name="g"></param>
 5    /// <param name="value"></param>

 6    private void DrawBarChart(Graphics g, double value)
 7    {
 8        double val = value > 100 ? 100 : value;
 9
10        // Compute size and location
11        Point pt = new Point();
12        int width = 100;
13        int height = 16;
14        int eclipseWidth = 4;
15
16        Rectangle r1 = new Rectangle(pt, new Size(eclipseWidth, height));
17        Rectangle r2 = r1;
18        r2.X += width;
19        Rectangle r3 = r1;
20        r3.X = r1.X + (int)(width * (val / 100.0));
21
22        Rectangle r4 = r1;
23        r4.X = pt.X + (eclipseWidth / 2);
24        r4.Width = width;
25
26        Rectangle r5 = r4;
27        r5.Width = (int)(width * (val / 100.0));
28
29        Pen redPen = new Pen(Color.Red);
30        Pen greenPen = new Pen(Color.Green);
31
32        GraphicsPath gp1 = new GraphicsPath();
33        gp1.AddEllipse(r1);
34        GraphicsPath gp2 = new GraphicsPath();
35        gp2.AddEllipse(r2);
36
37        Region rgn1 = new Region(r4);
38        rgn1.Exclude(gp1);
39        rgn1.Union(gp2);
40
41
42        gp1 = new GraphicsPath();
43        gp1.AddEllipse(r1);
44        gp2 = new GraphicsPath();
45        gp2.AddEllipse(r3);
46
47        Region rgn2 = new Region(r5);
48        rgn2.Exclude(gp1);
49        rgn2.Union(gp2);
50
51        LinearGradientBrush lgb = new LinearGradientBrush(pt, new Point(pt.X, pt.Y + height), Color.Black, Color.Yellow);
52        lgb.SetBlendTriangularShape(0.5f1.0f);
53        
54        g.FillRegion(lgb, rgn1);
55
56        lgb = new LinearGradientBrush(pt, new Point(pt.X, pt.Y + height), Color.Navy, Color.Green);
57        if (value > 100)
58        {
59            lgb = new LinearGradientBrush(pt, new Point(pt.X, pt.Y + height), Color.Navy, Color.Red);
60        }

61        lgb.SetBlendTriangularShape(0.5f1.0f);
62        g.FillRegion(lgb, rgn2);
63
64
65        PathGradientBrush pb = new PathGradientBrush(gp1);
66        pb.SurroundColors = new Color[] { Color.Gray };
67        pb.CenterColor = pb.CenterColor = Color.LightYellow;
68
69        g.FillEllipse(pb, r1);
70
71        Font f = new Font(FontFamily.GenericSansSerif,9.0f);
72
73        string text = string.Format("{0}%", value);
74        if (value > 100)
75        {
76            text = "过期未完成";
77        }

78        
79        Color fntColor = Color.White;
80        if (val < 50)
81        {
82            fntColor = Color.Purple;
83        }

84        
85        RectangleF textRect = this.ComputeTextRectangle(g, r4, f, text);
86        g.DrawString(text, f, new SolidBrush(fntColor), textRect, StringFormat.GenericTypographic); 
87
88    }

需要把所画的图像由页面展示出来:

 1    protected void Page_Load(object sender, EventArgs e)
 2    {
 3        Response.Clear();
 4        Response.ContentType = "image/jpeg";
 5
 6        string error = Request["error"];
 7        string progress = Request["progress"];
 8
 9        MemoryStream ms = new MemoryStream();
10
11        Bitmap bmp = new Bitmap(110,17);
12        using (Graphics g = Graphics.FromImage(bmp))
13        {
14            g.Clear(Color.White);
15
16            if (string.IsNullOrEmpty(progress))
17            {
18                error = "1";
19            }

20
21            if (!string.IsNullOrEmpty(error))
22            {
23                this.DrawError(g, int.Parse(error));
24            }

25            else
26            {
27                this.DrawBarChart(g, double.Parse(progress));
28            }

29        }

30
31        bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
32    }

效果图如下,里面有比较明显的锯齿,主要是所选取的位图尺寸比较小,如果取大一些再来缩小展现的话,效果应该会好些。