zoukankan      html  css  js  c++  java
  • gdi+ 折线图

         
    panle  为画图的容器,
    data 每个项为数据输入格式为 1,2,3,4 
    time  格式为 "10:20,10:30,10:40 "
    name 格式为 "项目1,项目2";

       

            
    static public void StaDrawHdImage(Panel ImagePanle,ArrayList  data,string time,string names)
           


               Imagewidth 
    = ImagePanle.Width;
               ImageHeight 
    = ImagePanle.Height;
                
               Bitmap bm 
    = new Bitmap(ImagePanle.Width,ImagePanle .Height);
              Graphics  g
    =Graphics.FromImage(bm);
              g.SmoothingMode 
    = SmoothingMode.AntiAlias;
              Rectangle toptile 
    = new Rectangle(new Point(00), new Size(Imagewidth, ImageHeight));
              Brush brtop 
    = new SolidBrush(Color.FromArgb(59110165));
              g.FillRectangle(brtop, toptile);
              Brush NameBrush
    =new SolidBrush (Color .FromArgb (255,255,255));
             g.DrawString(
    "烟尘黑度监视分析系统"new Font("宋体",16), NameBrush, ImagePanle.Width / 2 - 13010);

                
    /*画箭头*/
             
             g.DrawLine(
    new Pen (NameBrush), new Point(localLeft - 1, LocalTop - 10), new Point(localLeft - 1, ImagePanle.Height - 30));
             g.DrawLine(
    new Pen(NameBrush), new Point(localLeft - 1, ImageHeight - LocalButtom), new Point(Imagewidth - localRight+10, ImageHeight - LocalButtom));
              g.DrawLine(
    new Pen(NameBrush), new Point(localLeft-1, LocalTop-10), new Point(localLeft-1+2, LocalTop-10+2));
             g.DrawLine(
    new Pen(NameBrush), new Point(localLeft-1, LocalTop-10), new Point(localLeft-1-2, LocalTop-10+2));
             g.DrawLine (
    new Pen (NameBrush),new Point(Imagewidth-localRight+10,ImageHeight -LocalButtom),new Point (Imagewidth-localRight+10-2,ImageHeight-LocalButtom-2));
              g.DrawLine(
    new Pen(NameBrush), new Point(Imagewidth - localRight + 10, ImageHeight - LocalButtom), new Point(Imagewidth - localRight + 10 - 2, ImageHeight - LocalButtom + 2));
              
                
    /*画垂直刻度*/
              
    for (int i = 0; i <5; i++)
              
    {  
                  
    int  kd=(ImageHeight-LocalTop-LocalButtom) /5;
              g.DrawLine(
    new Pen(NameBrush), new Point(localLeft-1, LocalTop+kd * i ), new Point(localLeft-4, LocalTop+kd * i ) );
              g.DrawString (Convert.ToString (
    5-i).ToString (),new Font("宋体",9),NameBrush,new Point (localLeft-10, LocalTop+kd * i-4));
         
              }

            
                
    /*画水平刻度*/

              
    string[] temptimes = time.Split(new char[] ',' });
              
    for (int j = 0; j <temptimes.Length; j++)
              
    {

                  
    float kds = (float)(Imagewidth - localLeft - localRight) / (float)temptimes.Length; ;

                  
    if (j < temptimes.Length)
                  
    {
                      g.DrawLine(
    new Pen(NameBrush), new PointF((float)(localLeft - 1 + kds * j), ImageHeight - LocalButtom), new PointF((float)(localLeft - 1 + kds * j), ImageHeight - LocalButtom + 4));
                      g.DrawString(temptimes[j], 
    new Font("宋体"9), NameBrush, new PointF((float)(localLeft - 1 + kds * j - 10), ImageHeight - LocalButtom + 8));
                  }

              }

              Rectangle ra
    =new Rectangle (new Point (localLeft,LocalTop),new Size(Imagewidth-localLeft-localRight,ImageHeight-LocalButtom -LocalTop));
               Brush br 
    = new LinearGradientBrush(ra,Color .FromArgb (0,0,0),Color.FromArgb(255,255,255), LinearGradientMode.Vertical);
              
              g.FillRectangle(br, ra);

                
    /*画线*/ 
                  
    int  kdy=(ImageHeight-LocalTop-LocalButtom) /5;
                  
    float kdx = (float)(Imagewidth - localLeft - localRight) / (float)temptimes.Length;
                  
                
    // PointF[] poins=new PointF[data.Length];
                 for (int i = 0; i < data.Count; i++)
                 
    {
                     Brush databrush 
    = new SolidBrush(colordata [i]);
                     
    string[] temp =data[i].ToString ().Split(new char[] ',' });
                     PointF[] poins 
    = new PointF[temp.Length];
                      
    for (int j=0;j<temp.Length ;j++)
                     

                         
                      poins[ j] 
    = new PointF((float)(localLeft + kdx * j), LocalTop + kdy * (5 -int.Parse (temp[j])));
                     }

                     g.DrawLines(
    new Pen(databrush), poins);
                     
                     
                 }

                    
    /* poins[0] = new PointF((float)(localLeft + kdx * 0), LocalTop + kdy * (5 - 2));
                  poins[1] = new PointF((float)(localLeft + kdx * 1), LocalTop + kdy * (5 - 1));
                  poins[2] = new PointF((float)(localLeft + kdx * 2), LocalTop+ kdy * (5 - 3));
                     
    */

                 
                            
                 Brush b
    =new SolidBrush(Color.Black );
                 
               g.FillRectangle(NameBrush,
    new Rectangle (new Point(Imagewidth-200,ImageHeight-200),new Size (170,170)));
               
    if (names != null)
               
    {
                   
    string[] tempName = names.Split(new char[] ',' });
                   
    for (int l = 0; l < tempName.Length; l++)
                   
    {
                       g.FillRectangle(
    new SolidBrush(colordata[l]), new Rectangle(new Point(Imagewidth - 200 + 20, ImageHeight - 200 + 20 * l + 10 * (l + 1)), new Size(2020)));
                       g.DrawString(tempName[l].ToString(), 
    new Font("宋体"9), b, new PointF(Imagewidth - 200 + 60, ImageHeight - 200 + 20 * l + 10 * (l + 1)));

                   }

               }

             
                ImagePanle.BackgroundImage 
    = bm;
               

           }



  • 相关阅读:
    demo2动态加载显示商品详情页
    demo1 动态显示view或弹框 动态隐藏view或弹框
    ios 继承UITableViewController,更改tableview样式
    ios数组基本用法和排序大全
    demo1 动态显示view或弹框 动态隐藏view或弹框
    ios数组基本用法和排序大全
    爬虫从入门到放弃
    软件测试方法
    熟悉项目需求,要知道产品增删修改了哪些内容,才会更快更准确的在该项目入手。
    速达光耀开发版软件关于360安全卫士杀掉的说明
  • 原文地址:https://www.cnblogs.com/gwazy/p/771702.html
Copyright © 2011-2022 走看看