zoukankan      html  css  js  c++  java
  • .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
  • 相关阅读:
    spark on yarn 无法提交任务问题
    git rebase 操作撤销
    vim 删除屏蔽行
    mysql 登录远程数据库 失败
    springboot拦截器中获取配置文件值
    根据经纬度获取地址 :位置名称 区 市 省 国家 邮编
    element-ui upload组件上传
    java读写excel文件( POI解析Excel)
    easyui+themeleaf 分页查询实现
    java生成二维码
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1625926.html
Copyright © 2011-2022 走看看