资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 软件开发 >
Advertisement
文章正文

关于.Net画图的求救(C#)

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   

用.NET做画图程序,大家给一个意见哈.  
   
  主要是画一个坐标系,N多点,编程将其连接起来,用来分析其参数.

网友回答:

发表者:pxk

好像是System.Drawing

发表者:lhx1977

using   System;  
  using   System.Drawing;    
  using   System.Web.Services;  
  using   System.Data;  
  namespace   localhost  
  {  
  ///   <summary>  
  ///   myDraw   的摘要说明。  
  ///   </summary>  
  public   class   myDraw  
  {  
  public   string   thefullname;  
  public   string   theharfname;  
  int   blockwidth;  
  int   blockwidth1;  
  int   blockheight;  
  int   maxValue;  
  int   chart_left;  
  int   chart_top;  
                       
  public   myDraw()  
  {  
  //  
  //   TODO:   在此处添加构造函数逻辑  
  //  
  blockwidth=20;  
  blockwidth1=40;  
  blockheight=200;  
  chart_left=80;  
  chart_top=50;  
   
  }  
  public   string   CreateLineImage(DataTable   dt){  
  int   ww=dt.Rows.Count*blockwidth1+100;  
  if   (ww<=200)   ww=200;  
       Bitmap   image=new   Bitmap(ww,380);    
       Graphics   g=Graphics.FromImage(image);    
  maxValue=0;  
  for   (int   i=0;i<dt.Rows.Count;i++)  
  {  
  string   pp=dt.Rows[i][1].ToString();  
  int   tt=System.Convert.ToInt32(pp);  
  if(   maxValue<tt)   maxValue=tt;  
  }              
  if   (maxValue==0)   maxValue=1;  
                 
     g.Clear(Color.FromArgb(239,235,214)   );    
     g.DrawString("销售排行",new   Font("Courier   New",   10),new   SolidBrush(Color.DarkBlue),20,5);    
     //Graphics   类还有很多绘图方法可以绘制   直线、曲线、圆等等    
  Pen   blackPen1=new   Pen(Color.Cyan   ,1);  
  g.DrawLine(blackPen1,chart_left-20,chart_top,chart_left+dt.Rows.Count*blockwidth1,chart_top);  
  g.DrawString(maxValue.ToString(),new   Font("Courier   New",   9),new   SolidBrush(Color.DarkBlue),chart_left-80,chart_top);    
  Pen   blackPen=new   Pen(Color.Black   ,1);  
  g.DrawLine(blackPen,chart_left-20,chart_top-10,chart_left-20,chart_top+blockheight);  
  g.DrawLine(blackPen,new   Point(chart_left-17,chart_top-3),new   Point(chart_left-20,chart_top-10));  
  g.DrawLine(blackPen,new   Point(chart_left-23,chart_top-3),new   Point(chart_left-20,chart_top-10));  
  g.DrawLine(blackPen,chart_left-20,chart_top+blockheight,chart_left+dt.Rows.Count*blockwidth1   ,chart_top+blockheight);  
  g.DrawLine(blackPen,new   Point(chart_left+dt.Rows.Count*blockwidth1-4,chart_top+blockheight-4),new   Point(chart_left+dt.Rows.Count*blockwidth1   ,chart_top+blockheight));  
  g.DrawLine(blackPen,new   Point(chart_left+dt.Rows.Count*blockwidth1-4,chart_top+blockheight+4),new   Point(chart_left+dt.Rows.Count*blockwidth1   ,chart_top+blockheight));  
  Point[]   pt=new   Point[dt.Rows.Count];  
  for   (int   i=0;i<dt.Rows.Count;i++)  
  {  
  int   tt=System.Convert.ToInt32(dt.Rows[i][1].ToString());  
  double   mm=(System.Convert.ToDouble(tt)/System.Convert.ToDouble(maxValue));  
  int   ht=System.Convert.ToInt32(blockheight*mm);  
          pt[i].X=chart_left+blockwidth1*i-20;  
  pt[i].Y=chart_top+blockheight-ht;  
  string   name=dt.Rows[i][0].ToString();  
  if   (name.Length<4)  
  {  
  g.DrawString(name,new   Font("Courier   New",   9),new   SolidBrush(Color.DarkBlue),chart_left+blockwidth1*i-30,chart_top+blockheight+10);    
  }  
  else{  
  g.DrawString(name,new   Font("Courier   New",   9),new   SolidBrush(Color.DarkBlue),chart_left+blockwidth1*i-40,chart_top+blockheight+20);    
  }  
   
  }    
  Pen   redPen=new   Pen(Color.Red     ,1);  
  g.DrawLines(redPen,pt);    
   
   
     image.Save(thefullname,System.Drawing.Imaging.ImageFormat.Gif);  
  return   theharfname;  
      
  }  
   
  public   string     CreateImage(DataTable   dt)    
       {    
    int   ww=dt.Rows.Count*blockwidth1+100;  
    if   (ww<=200)   ww=200;  
       Bitmap   image=new   Bitmap(ww,380);    
       Graphics   g=Graphics.FromImage(image);    
    maxValue=0;  
  for   (int   i=0;i<dt.Rows.Count;i++){  
  string   pp=dt.Rows[i][1].ToString();  
  int   tt=System.Convert.ToInt32(pp);  
  if(   maxValue<tt)   maxValue=tt;  
  }              
  if   (maxValue==0)   maxValue=1;  
                 
     g.Clear(Color.FromArgb(239,235,214)   );    
     g.DrawString("销售排行",new   Font("Courier   New",   10),new   SolidBrush(Color.DarkBlue),20,5);    
     //Graphics   类还有很多绘图方法可以绘制   直线、曲线、圆等等    
  Pen   blackPen1=new   Pen(Color.Cyan   ,1);  
  g.DrawLine(blackPen1,chart_left-20,chart_top,chart_left+dt.Rows.Count*blockwidth1,chart_top);  
  g.DrawString(maxValue.ToString(),new   Font("Courier   New",   9),new   SolidBrush(Color.DarkBlue),chart_left-80,chart_top);    
  Pen   blackPen=new   Pen(Color.Black   ,1);  
  g.DrawLine(blackPen,chart_left-20,chart_top-10,chart_left-20,chart_top+blockheight);  
          g.DrawLine(blackPen,new   Point(chart_left-17,chart_top-3),new   Point(chart_left-20,chart_top-10));  
  g.DrawLine(blackPen,new   Point(chart_left-23,chart_top-3),new   Point(chart_left-20,chart_top-10));  
                          g.DrawLine(blackPen,chart_left-20,chart_top+blockheight,chart_left+dt.Rows.Count*blockwidth1   ,chart_top+blockheight);  
  g.DrawLine(blackPen,new   Point(chart_left+dt.Rows.Count*blockwidth1-4,chart_top+blockheight-4),new   Point(chart_left+dt.Rows.Count*blockwidth1   ,chart_top+blockheight));  
  g.DrawLine(blackPen,new   Point(chart_left+dt.Rows.Count*blockwidth1-4,chart_top+blockheight+4),new   Point(chart_left+dt.Rows.Count*blockwidth1   ,chart_top+blockheight));  
   
  for   (int   i=0;i<dt.Rows.Count;i++)  
  {  
  int   tt=System.Convert.ToInt32(dt.Rows[i][1].ToString());  
  double   mm=(System.Convert.ToDouble(tt)/System.Convert.ToDouble(maxValue));  
                                  int   ht=System.Convert.ToInt32(blockheight*mm);  
  g.DrawRectangle   (blackPen,chart_left+blockwidth1*i,chart_top+blockheight-ht,blockwidth,ht);  
  g.FillRectangle(Brushes.Red,new   Rectangle(chart_left+blockwidth1*i,chart_top+blockheight-ht,blockwidth,ht));  
  string   name=dt.Rows[i][0].ToString();  
  for(int   j=0;j<name.Length;j++)  
  {  
  g.DrawString(name.Substring(j,1),new   Font("Courier   New",   9),new   SolidBrush(Color.DarkBlue),chart_left+blockwidth1*i,chart_top+blockheight+10+14*j);    
  }  
   
  }    
     image.Save(thefullname,System.Drawing.Imaging.ImageFormat.Gif);  
  return   theharfname;  
     }    
   
  }  
  }  
 

发表者:105910556

用水晶报表画图     或者用office带的控件


 

 
热门推荐笔记本: 神舟笔记本
相关文章:
笔记本相关:
IT技术文章:
webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
©2007 popbb.net All Rights Reserved