日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > C# >内容正文

C#

Windows Mobile中实现统计图形的绘制(C#版,柱状图)

發(fā)布時(shí)間:2025/3/20 C# 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Windows Mobile中实现统计图形的绘制(C#版,柱状图) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

  首先,建立繪圖類,如下:

1 /// <summary> 2 /// 繪制柱狀圖 3 /// </summary> 4 /// <param name="ds">DataTable中第一列為數(shù)據(jù)列,第二列為對(duì)應(yīng)的名稱</param> 5 /// <param name="xName">X軸名稱</param> 6 /// <param name="yName">Y軸名稱</param> 7 /// <returns>位圖對(duì)象</returns> 8 public Bitmap GetDrawRectangleForStat(DataSet ds, string xName, string yName) 9 { 10 Bitmap cBmp = new Bitmap(471, 367); //創(chuàng)建畫布寬度為471,高度為367的Bitmap實(shí)例 11 Graphics cGraphic; 12 Color[] cColor = new Color[] { Color.Red, Color.Blue, Color.Green, Color.Gray, Color.LightCoral, Color.Gold, Color.Brown, Color.Cyan, Color.Lime, Color.Peru, Color.Magenta, Color.Sienna, Color.Chocolate, Color.PeachPuff, Color.Orange, Color.DarkGoldenrod, Color.Olive, Color.DarkSeaGreen, Color.SpringGreen, Color.Teal, Color.CadetBlue, Color.RoyalBlue, Color.DeepPink, Color.LightGray, Color.MediumVioletRed, Color.Orchid, Color.MediumSlateBlue, Color.White, Color.LightSteelBlue, Color.DarkSlateGray, Color.GreenYellow, Color.DarkKhaki, Color.RosyBrown, Color.Navy, Color.Indigo, Color.HotPink }; //36種顏色 13 14 Pen cPen; 15 SolidBrush cSolidBrush; 16 Font bFont = new Font("Tahoma", 14, FontStyle.Bold); //軸標(biāo)字體 17 Font sFont = new Font("Tahoma", 14, FontStyle.Bold); //統(tǒng)計(jì)數(shù)值字體 18 Font fFont = new Font("Tahoma", 14, FontStyle.Bold); //統(tǒng)計(jì)項(xiàng)值字體 19 20 StringFormat cFormat = new StringFormat(); 21 RectangleF cRect; 22 int RowNum = 0; 23 int iLoop = 0; 24 int i = 0; 25 int cValue = 0; 26 int MaxValue = 0; 27 28 //定義Y軸,Y上(42,15)~Y下(42,317),Y軸長(zhǎng)從17到317共300 29 int xPu = 42; //Y軸上(Up)點(diǎn)X坐標(biāo) 30 int yPu = 15; //Y軸上(Up)點(diǎn)Y坐標(biāo) 31 int xPd = 42; //Y軸下(Down)點(diǎn)X坐標(biāo) 32 int yPd = 317; //Y軸下(Down)點(diǎn)Y坐標(biāo) 33 34 //定義X軸,X左(42,317)~X右(448,317),X軸上從42到448共406 35 int xPl = 42; //X軸左(Left)點(diǎn)X坐標(biāo) 36 int yPl = 317; //X軸左(Left)點(diǎn)Y坐標(biāo) 37 int xPr = 448; //X軸右(Right)點(diǎn)X坐標(biāo) 38 int yPr = 317; //X軸右(Right)點(diǎn)Y坐標(biāo) 39 40 //定義柱圖 41 //int xStart = 57; //首根柱圖開始的X軸坐標(biāo) 42 //int cWidth = 20; //柱圖寬度 43 //int cSpace = 15; //柱圖間距 44 int xStart = 67; //首根柱圖開始的X軸坐標(biāo) 45 int cWidth = 40; //柱圖寬度 46 int cSpace = 25; //柱圖間距 47 48 cGraphic = Graphics.FromImage(cBmp); 49 cGraphic.Clear(Color.Snow); 50 51 //畫軸線 52 cPen = new Pen(Color.Black, 3); 53 cSolidBrush = new SolidBrush(Color.Black); 54 cGraphic.DrawLine(cPen, xPu, yPu, xPd, yPd); //Y軸 55 cGraphic.DrawLine(cPen, xPl, yPl, xPr, yPr); //X軸 56 57 //畫軸向 58 cGraphic.DrawLine(cPen, xPu, yPu - 3, xPu - 4, yPu + 3); //Y軸向 59 cGraphic.DrawLine(cPen, xPu, yPu - 3, xPu + 4, yPu + 3); 60 cGraphic.DrawLine(cPen, xPr + 3, yPr, xPr - 4, yPr - 3); //X軸向 61 cGraphic.DrawLine(cPen, xPr + 3, yPr, xPr - 4, yPr + 3); 62 63 //畫軸標(biāo) 64 cFormat.FormatFlags = StringFormatFlags.NoClip; 65 cGraphic.DrawString(yName, bFont, cSolidBrush, 5, 45, cFormat); //Y軸標(biāo) 66 cGraphic.DrawString(xName, bFont, cSolidBrush, 392, 332, cFormat); //X軸標(biāo) 67 68 //畫軸心值 69 cGraphic.DrawString("0", sFont, cSolidBrush, xPd - 5, yPd + 3, cFormat); 70 71 RowNum = ds.Tables[0].Rows.Count - 1; 72 73 for (i = 0; i <= RowNum; i++) 74 { 75 if (MaxValue < Int32.Parse(ds.Tables[0].Rows[i][0].ToString())) 76 { 77 MaxValue = Int32.Parse(ds.Tables[0].Rows[i][0].ToString()); 78 } 79 80 //畫柱圖 81 cPen = new Pen(cColor[i], 3); 82 cSolidBrush = new SolidBrush(cColor[i]); 83 cValue = Int32.Parse(ds.Tables[0].Rows[i][0].ToString()) * ((yPd - yPu) / MaxValue); 84 cGraphic.DrawRectangle(cPen, xStart + (cWidth + cSpace) * iLoop, yPd - cValue, cWidth, cValue - 2); //減2的目的:使柱圖的下邊沿不擋住X軸 85 cGraphic.FillRectangle(cSolidBrush, xStart + (cWidth + cSpace) * iLoop, yPd - cValue, cWidth, cValue - 2); 86 87 //畫柱圖統(tǒng)計(jì)Y軸值 88 cGraphic.DrawString(ds.Tables[0].Rows[i][0].ToString(), sFont, cSolidBrush, xStart + (cWidth + cSpace) * iLoop - 2, yPd - cValue - 20, cFormat); 89 90 //畫柱圖統(tǒng)計(jì)X軸值 91 cRect = new RectangleF(xStart + (cWidth + cSpace) * iLoop, yPd + 1, cWidth + 10, 40); 92 cGraphic.DrawString(ds.Tables[0].Rows[i][1].ToString(), fFont, cSolidBrush, cRect, cFormat); 93 94 iLoop += 1; 95 } 96 97 return cBmp; 98 }

  然后,在Windows Mobile的窗體中加入PictureBox控件,調(diào)用繪圖方法,將圖形展現(xiàn)到PictureBox控件中。

轉(zhuǎn)載于:https://www.cnblogs.com/eagle927183/archive/2010/04/08/1706964.html

總結(jié)

以上是生活随笔為你收集整理的Windows Mobile中实现统计图形的绘制(C#版,柱状图)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。