画一个立体的柱图

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

 1 ExpandedBlockStart.gif ContractedBlock.gif /**/ /// <summary>
 2InBlock.gif    /// Draw Bar Chart
 3InBlock.gif    /// </summary>
 4InBlock.gif    /// <param name="g"></param>
 5ExpandedBlockEnd.gif    /// <param name="value"></param>

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

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

78InBlock.gif        
79InBlock.gif        Color fntColor = Color.White;
80InBlock.gif        if (val < 50)
81ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
82InBlock.gif            fntColor = Color.Purple;
83ExpandedSubBlockEnd.gif        }

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

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

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

20InBlock.gif
21InBlock.gif            if (!string.IsNullOrEmpty(error))
22ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
23InBlock.gif                this.DrawError(g, int.Parse(error));
24ExpandedSubBlockEnd.gif            }

25InBlock.gif            else
26ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
27InBlock.gif                this.DrawBarChart(g, double.Parse(progress));
28ExpandedSubBlockEnd.gif            }

29ExpandedSubBlockEnd.gif        }

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

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

转载于:https://www.cnblogs.com/FirePhoenix/archive/2007/02/15/651044.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值