• .NET : 如何利用GDI+绘制折线图


    这是今天课堂上讲的一个范例小程序。 其实很多图表控件大多也是这样画出来的。           
                //如何从零开始构造一个图片
                Bitmap b = new Bitmap(600, 400);
                Graphics bg = Graphics.FromImage(b);
                //背景颜色先清除掉
                bg.Clear(Color.LightGray);
    
                //先画横轴
                bg.DrawLine(
                    new Pen(Color.Black),
                    new Point(10, 380),
                    new Point(580, 380));
    
                bg.DrawLine(
                    new Pen(Color.Black),
                    new Point(570, 370),
                    new Point(580, 380));
    
                bg.DrawLine(
                    new Pen(Color.Black),
                    new Point(570, 390),
                    new Point(580, 380));
    
    
                //再画纵轴
                bg.DrawLine(
                    new Pen(Color.Black),
                    new Point(20, 390),
                    new Point(20, 20));
    
                bg.DrawLine(
                    new Pen(Color.Black),
                    new Point(10, 30),
                    new Point(20, 20));
                bg.DrawLine(
                    new Pen(Color.Black),
                    new Point(30, 30),
                    new Point(20, 20));
    
    
                //画我们那条趋势线
                List<Point> points = new List<Point>()
                {
                    new Point(20,380),
                    new Point(40,365),
                    new Point(55,350),
                    new Point(100,300),
                    new Point(200,120),
                    new Point(570,30)};
    
                bg.DrawLines(
                    new Pen(Color.Red),
                    points.ToArray());
    
    
                foreach (var item in points)
                {
                    item.Offset(-10, -10);
    
                    bg.FillEllipse(
                        new SolidBrush(Color.Yellow),
                        new Rectangle(item,new Size(20,20)));
    
    
                    item.Offset(5, 5);
                    bg.DrawString(
                        item.Y.ToString(),
                        new Font("Arial", 6),
                        new SolidBrush(Color.Blue),
                        item);
    
                }
    
                bg.Dispose();
    
                b.Save("demo.bmp");

    demo
  • 相关阅读:
    命令行程序测试自动化
    微软的PivotViewer控件编程续
    使用Autofac实现依赖注射及Ioc
    微软的PivotViewer控件编程
    求最大公约数(GCD)的两种算法
    编译原理学习笔记一(待续)
    如果你想创业,又担心腾讯照抄你的好点子的话,可以看看下面的文章。
    从测试的角度来重新反思我们自己的程序以及我们的程序员之路——“通过追本溯源来进行前瞻性思考”
    Ubuntu11.10安装飞信
    2012.3.27《JAVA程序设计教程》
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1625926.html
Copyright © 2020-2023  润新知