c#.net画曲线图(坐标)

 

using System.Drawing.Imaging;
using System.Drawing.Drawing2D;


  //数据/月份
  public ArrayList arrData=new ArrayList();
  public ArrayList arrMonth=new ArrayList();
  //定义幕布高宽
  private int iCanvasWidth=400;
  private int iCanvasHeight=300;
  //x轴的间距
  private int iX=30;
  //y轴间距
  private int iY=15;

 

  public void InitArray()
  {
   for(int i=0;i<6;i++)
    arrMonth.Add(i+1);
            arrData.Add(200);
   arrData.Add(180);
   arrData.Add(285);
   arrData.Add(290);
   arrData.Add(275);
   arrData.Add(350);

  }

//   //pen 画线
//   Pen myPen = new Pen(Color.Black);
//   Graphics g = this.CreateGraphics();
//   g.DrawEllipse(myPen, 20, 30, 10, 50);
//
//   Graphics g1 = this.CreateGraphics();
//   SolidBrush myBrush = new SolidBrush(Color.Red);
//   g1.FillEllipse(myBrush,20,30,40,40);
//   g1.FillRectangle(myBrush,70,70,10,30);
   this.InitArray();

   Bitmap bitmap= new Bitmap(iCanvasWidth, iCanvasHeight,PixelFormat.Format24bppRgb);
   //Graphics g=Graphics.FromImage(bitmap);
   Graphics g=this.CreateGraphics();
   g.Clear(Color.White);
   
   Font font = new Font("MS UI Gothic",12);
   SolidBrush brush = new SolidBrush(Color.Black);
   Pen pen = new Pen(Color.Black);
   pen.EndCap = LineCap.ArrowAnchor;
   pen.DashStyle = DashStyle.Solid;
   //坐标轴
            g.DrawLine(pen,20,220,420,220);
   g.DrawLine(pen,20,220,20,20);

   //x轴标格
   g.DrawLine(Pens.Black,20+iX*1,220,20+iX*1,220-2);
   g.DrawLine(Pens.Black,20+iX*2,220,20+iX*2,220-2);
   g.DrawLine(Pens.Black,20+iX*3,220,20+iX*3,220-2);
   g.DrawLine(Pens.Black,20+iX*4,220,20+iX*4,220-2);
   g.DrawLine(Pens.Black,20+iX*5,220,20+iX*5,220-2);
   g.DrawLine(Pens.Black,20+iX*6,220,20+iX*6,220-2);

   //y轴标格
   g.DrawLine(Pens.Black, 20, 220 - iY*1, 20 + 2, 220 - iY*1);
   g.DrawLine(Pens.Black, 20, 220 - iY*2, 20 + 2, 220 - iY*2);
   g.DrawLine(Pens.Black, 20, 220 - iY*3, 20 + 2, 220 - iY*3);
   g.DrawLine(Pens.Black, 20, 220 - iY*4, 20 + 2, 220 - iY*4);
   g.DrawLine(Pens.Black, 20, 220 - iY*5, 20 + 2, 220 - iY*5);
   g.DrawLine(Pens.Black, 20, 220 - iY*6, 20 + 2, 220 - iY*6);

   //
   double dblX1=20;
   double dblY1=220;
   for(int i=0;i<arrData.Count;i++)
   {
    double dblData=Convert.ToDouble(arrData[i]);
    double dblY2=220-dblData*15/200;
    
    double dblX2=20+iX*Convert.ToInt32(arrMonth[i]);
    if(i!=0)
    {
     if(i<arrData.Count-1)
     {
      g.DrawLine(Pens.Black,float.Parse(dblX1.ToString()),float.Parse(dblY1.ToString()),float.Parse(dblX2.ToString()),float.Parse(dblY2.ToString()));
     }
     else
     {
      g.DrawLine(pen,float.Parse(dblX1.ToString()),float.Parse(dblY1.ToString()),float.Parse(dblX2.ToString()),float.Parse(dblY2.ToString()));
     }
    }
    
    dblX1=dblX2;
    dblY1=dblY2;
   }
 
  }

 }
}
 

评论 4 您还未登录,请先 登录 后发表或查看评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

wthorse

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值