{"id":126,"date":"2010-06-18T09:46:15","date_gmt":"2010-06-18T09:46:15","guid":{"rendered":"069059b7ef840f0c74a814ec9237b6ec"},"modified":"2010-06-18T09:46:15","modified_gmt":"2010-06-18T09:46:15","slug":"","status":"publish","type":"post","link":"https:\/\/www.xiaobo.li\/notes\/archives\/126","title":{"rendered":"C#\u4e2d\u7528GDI+\u751f\u6210\u997c\u72b6\u56fe\u548c\u67f1\u72b6\u56fe"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\"><span class=\"Apple-style-span\" style=\"word-spacing: 0px; font: 16px simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; widows: 2; orphans: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"><span class=\"Apple-style-span\" style=\"font-size: 13px; color: rgb(75,75,75); line-height: 20px\">using System;<br \/>using System.IO;\/\/\u7528\u4e8e\u6587\u4ef6\u5b58\u53d6 <\/span><br \/>\n<br \/>using System.Data;\/\/\u7528\u4e8e\u6570\u636e\u8bbf\u95ee <\/span><br \/>\n<br \/>using System.Drawing;\/\/\u63d0\u4f9b\u753bGDI+\u56fe\u5f62\u7684\u57fa\u672c\u529f\u80fd <br \/>using System.Drawing.Text;\/\/\u63d0\u4f9b\u753bGDI+\u56fe\u5f62\u7684\u9ad8\u7ea7\u529f\u80fd <br \/>using System.Drawing.Drawing2D;\/\/\u63d0\u4f9b\u753b\u9ad8\u7ea7\u4e8c\u7ef4\uff0c\u77e2\u91cf\u56fe\u5f62\u529f\u80fd <br \/>using System.Drawing.Imaging;\/\/\u63d0\u4f9b\u753bGDI+\u56fe\u5f62\u7684\u9ad8\u7ea7\u529f\u80fd <br \/>namespace lc.laili.Web.Code<br \/>{<br \/>\/\/\/ &lt;summary&gt;<br \/>\/\/\/ MyImage \u7684\u6458\u8981\u8bf4\u660e\u3002<br \/>\/\/\/ &lt;\/summary&gt;<br \/>public class MyImage<br \/>{<br \/>public MyImage()<br \/>{<br \/>&nbsp;&nbsp; \/\/<br \/>&nbsp;&nbsp; \/\/ TODO: \u5728\u6b64\u5904\u6dfb\u52a0\u6784\u9020\u51fd\u6570\u903b\u8f91<br \/>&nbsp;&nbsp; \/\/<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">}<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">\/\/\/ &lt;summary&gt;<br \/>\/\/\/ \u6570\u636e\u6e90\u662fPieChartValue\u5bf9\u8c61\u7684\u997c\u72b6\u56fe<br \/>\/\/\/ &lt;\/summary&gt;<br \/>\/\/\/ &lt;param name=&quot;title&quot;&gt;\u997c\u72b6\u56fe\u5927\u6807\u9898&lt;\/param&gt;<br \/>\/\/\/ &lt;param name=&quot;subTitle&quot;&gt;\u997c\u72b6\u56fe\u5c0f\u6807\u9898&lt;\/param&gt;<br \/>\/\/\/ &lt;param name=&quot;width&quot;&gt;\u56fe\u5bbd&lt;\/param&gt;<br \/>\/\/\/ &lt;param name=&quot;height&quot;&gt;\u56fe\u9ad8&lt;\/param&gt;<br \/>\/\/\/ &lt;param name=&quot;Mydata&quot;&gt;PieChartValue\u5bf9\u8c61&lt;\/param&gt;<br \/>\/\/\/ &lt;returns&gt;\u997c\u72b6\u56fe\u8def\u5f84&lt;\/returns&gt;<br \/>public string Render(string title, string subTitle, int width, int height, PieChartValue[] Mydata)<br \/>{<br \/>&nbsp;&nbsp; const int SIDE_LENGTH = 400;<br \/>&nbsp;&nbsp; const int PIE_DIAMETER = 200;<br \/>&nbsp;&nbsp; \/\/DataTable dt = DataTable;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp; \/\/\u901a\u8fc7\u8f93\u5165\u53c2\u6570\uff0c\u53d6\u5f97\u997c\u56fe\u4e2d\u7684\u603b\u57fa\u6570 <br \/>&nbsp;&nbsp; float sumData = 0;<br \/>&nbsp;&nbsp; for (int i = 0; i &lt; Mydata.Length; i++)<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; sumData += Convert.ToSingle(Mydata[i].MValue);<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; \/\/\u4ea7\u751f\u4e00\u4e2aimage\u5bf9\u8c61\uff0c\u5e76\u7531\u6b64\u4ea7\u751f\u4e00\u4e2aGraphics\u5bf9\u8c61 <br \/>&nbsp;&nbsp; Bitmap bm = new Bitmap(width, height);<br \/>&nbsp;&nbsp; Graphics g = Graphics.FromImage(bm);<br \/>&nbsp;&nbsp; \/\/\u8bbe\u7f6e\u5bf9\u8c61g\u7684\u5c5e\u6027 <br \/>&nbsp;&nbsp; g.ScaleTransform((Convert.ToSingle(width)) \/ SIDE_LENGTH, (Convert.ToSingle(height)) \/ SIDE_LENGTH);<br \/>&nbsp;&nbsp; g.SmoothingMode = SmoothingMode.Default;<br \/>&nbsp;&nbsp; g.TextRenderingHint = TextRenderingHint.AntiAlias;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp; \/\/\u753b\u5e03\u548c\u8fb9\u7684\u8bbe\u5b9a <br \/>&nbsp;&nbsp; g.Clear(Color.White);<br \/>&nbsp;&nbsp; g.DrawRectangle(Pens.Black, 0, 0, SIDE_LENGTH - 1, SIDE_LENGTH - 1);<br \/>&nbsp;&nbsp; \/\/\u753b\u997c\u56fe\u6807\u9898 <br \/>&nbsp;&nbsp; g.DrawString(title, new Font(&quot;Tahoma&quot;, 14), Brushes.Black, new PointF(5, 5));<br \/>&nbsp;&nbsp; \/\/\u753b\u997c\u56fe\u7684\u56fe\u4f8b <br \/>&nbsp;&nbsp; g.DrawString(subTitle, new Font(&quot;Tahoma&quot;, 12), Brushes.Black, new PointF(7, 35));<br \/>&nbsp;&nbsp; \/\/\u753b\u997c\u56fe <br \/>&nbsp;&nbsp; float curAngle = 0;<br \/>&nbsp;&nbsp; float totalAngle = 0;<br \/>&nbsp;&nbsp; for (int j = 0; j &lt; Mydata.Length; j++)<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; curAngle = Convert.ToSingle(Mydata[j].MValue) \/ sumData * 360;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp;&nbsp; g.FillPie(new SolidBrush(ChartUtil.GetChartItemColor(j)), 100, 65, PIE_DIAMETER, PIE_DIAMETER, totalAngle, curAngle);<br \/>&nbsp;&nbsp;&nbsp; g.DrawPie(Pens.Black, 100, 65, PIE_DIAMETER, PIE_DIAMETER, totalAngle, curAngle);<br \/>&nbsp;&nbsp;&nbsp; totalAngle += curAngle;<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; \/\/\u753b\u56fe\u4f8b\u6846\u53ca\u5176\u6587\u5b57 <br \/>&nbsp;&nbsp; g.DrawRectangle(Pens.Black, 200, 300, 199, 99);<br \/>&nbsp;&nbsp; g.DrawString(&quot;\u56fe\u8868\u8bf4\u660e&quot;, new Font(&quot;Tahoma&quot;, 12, FontStyle.Bold), Brushes.Black, new PointF(200, 300));<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp; \/\/\u753b\u56fe\u4f8b\u5404\u9879 <br \/>&nbsp;&nbsp; PointF boxOrigin = new PointF(210, 330);<br \/>&nbsp;&nbsp; PointF textOrigin = new PointF(235, 326);<br \/>&nbsp;&nbsp; float percent = 0;<br \/>&nbsp;&nbsp; for (int k = 0; k &lt; Mydata.Length; k++)<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; g.FillRectangle(new SolidBrush(ChartUtil.GetChartItemColor(k)), boxOrigin.X, boxOrigin.Y, 20, 10);<br \/>&nbsp;&nbsp;&nbsp; g.DrawRectangle(Pens.Black, boxOrigin.X, boxOrigin.Y, 20, 10);<br \/>&nbsp;&nbsp;&nbsp; percent = Convert.ToSingle(Mydata[k].MValue) \/ sumData * 100;<br \/>&nbsp;&nbsp;&nbsp; g.DrawString(Mydata[k].MValue.ToString() + &quot; - &quot; + Mydata[k].Name.ToString() + &quot; (&quot; + percent.ToString(&quot;0&quot;) + &quot;%)&quot;, new Font(&quot;Tahoma&quot;, 10), Brushes.Black, textOrigin);<br \/>&nbsp;&nbsp;&nbsp; boxOrigin.Y += 15;<br \/>&nbsp;&nbsp;&nbsp; textOrigin.Y += 15;<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; \/\/\u56de\u6536\u8d44\u6e90 <br \/>&nbsp;&nbsp; g.Dispose();<br \/><span style=\"color: red; line-height: 19px\">\/\/\u6b64\u5904\u5b58\u50a8\u8def\u5f84\u9700\u8981\u81ea\u5df1\u6539<\/span><br \/>\n<br \/>&nbsp;&nbsp; System.Drawing.Image MyImage=(System.Drawing.Image)bm;<br \/>&nbsp;&nbsp; string TruePath= System.Web.HttpContext.Current.Server.MapPath(&quot;~\/images&quot;);<br \/>&nbsp;&nbsp; string TrueName=DateTime.Now.ToString(&quot;yyyyMMddhhmmss&quot;)+DateTime.Now.Millisecond;<br \/>&nbsp;&nbsp; MyImage.Save(TruePath+&quot;<a href=\"file:\/\/%22+truename+%22.jpg\/\" style=\"color: rgb(67,113,166)\">\\\\&quot;+TrueName+&quot;.jpg<\/a><br \/>\n&quot;, System.Drawing.Imaging.ImageFormat.Gif);<br \/>&nbsp;&nbsp; return &quot;~\/images\/&quot;+TrueName+&quot;.jpg&quot;;<br \/>}<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">\/\/\/ &lt;summary&gt;<br \/>\/\/\/ \u6570\u636e\u6e90\u662fBarChartValue\u5bf9\u8c61\u7684\u67f1\u72b6\u56fe<br \/>\/\/\/ &lt;\/summary&gt;<br \/>\/\/\/ &lt;param name=&quot;title&quot;&gt;\u5927\u6807\u9898&lt;\/param&gt;<br \/>\/\/\/ &lt;param name=&quot;subTitle&quot;&gt;\u5c0f\u6807\u9898&lt;\/param&gt;<br \/>\/\/\/ &lt;param name=&quot;width&quot;&gt;\u56fe\u5bbd&lt;\/param&gt;<br \/>\/\/\/ &lt;param name=&quot;height&quot;&gt;\u56fe\u9ad8&lt;\/param&gt;<br \/>\/\/\/ &lt;param name=&quot;Mydata&quot;&gt;BarChartValue\u5bf9\u8c61&lt;\/param&gt;<br \/>\/\/\/ &lt;returns&gt;\u67f1\u72b6\u56fe\u8def\u5f84&lt;\/returns&gt;<br \/>public string Render(string title, string subTitle, int width, int height, BarChartValue[] Mydata)<br \/>{<br \/>&nbsp;&nbsp; const int SIDE_LENGTH = 400;<br \/>&nbsp;&nbsp; const int CHART_TOP = 75;<br \/>&nbsp;&nbsp; const int CHART_HEIGHT = 200;<br \/>&nbsp;&nbsp; const int CHART_LEFT = 50;<br \/>&nbsp;&nbsp; const int CHART_WIDTH = 300;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp; \/\/\u8ba1\u7b97\u6700\u9ad8\u7684\u70b9 <br \/>&nbsp;&nbsp; float highPoint = 0;<br \/>&nbsp;&nbsp; for (int i=0; i &lt; Mydata.Length;i++ )<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; if (highPoint &lt; Convert.ToSingle(Mydata[i].MValue))<br \/>&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp; highPoint = Convert.ToSingle(Mydata[i].MValue);<br \/>&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; \/\/\u5efa\u7acb\u4e00\u4e2aGraphics\u5bf9\u8c61\u5b9e\u4f8b <br \/>&nbsp;&nbsp; Bitmap bm = new Bitmap(width, height);<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp;&nbsp; Graphics g = Graphics.FromImage(bm);<br \/>&nbsp;&nbsp;&nbsp; \/\/\u8bbe\u7f6e\u6761\u56fe\u56fe\u5f62\u548c\u6587\u5b57\u5c5e\u6027 <br \/>&nbsp;&nbsp;&nbsp; g.ScaleTransform((Convert.ToSingle(width)) \/ SIDE_LENGTH, (Convert.ToSingle(height)) \/ SIDE_LENGTH);<br \/>&nbsp;&nbsp;&nbsp; g.SmoothingMode = SmoothingMode.Default;<br \/>&nbsp;&nbsp;&nbsp; g.TextRenderingHint = TextRenderingHint.AntiAlias;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp;&nbsp; \/\/\u8bbe\u5b9a\u753b\u5e03\u548c\u8fb9 <br \/>&nbsp;&nbsp;&nbsp; g.Clear(Color.White);<br \/>&nbsp;&nbsp;&nbsp; g.DrawRectangle(Pens.Black, 0, 0, SIDE_LENGTH - 1, SIDE_LENGTH - 1);<br \/>&nbsp;&nbsp;&nbsp; \/\/\u753b\u5927\u6807\u9898 <br \/>&nbsp;&nbsp;&nbsp; g.DrawString(title, new Font(&quot;Tahoma&quot;, 14), Brushes.Black, new PointF(5, 5));<br \/>&nbsp;&nbsp;&nbsp; \/\/\u753b\u5c0f\u6807\u9898 <br \/>&nbsp;&nbsp;&nbsp; g.DrawString(subTitle, new Font(&quot;Tahoma&quot;, 12), Brushes.Black, new PointF(7, 35));<br \/>&nbsp;&nbsp;&nbsp; \/\/\u753b\u6761\u5f62\u56fe <br \/>&nbsp;&nbsp;&nbsp; float barWidth = CHART_WIDTH \/ (Mydata.Length * 2);<br \/>&nbsp;&nbsp;&nbsp; PointF barOrigin = new PointF(CHART_LEFT + (barWidth \/ 2), 0);<br \/>&nbsp;&nbsp;&nbsp; float barHeight = Mydata.Length;<br \/>&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; Mydata.Length; i++)<br \/>&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp; barHeight = Convert.ToSingle(Mydata[i].MValue) * 200 \/ highPoint * 1;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; barOrigin.Y = CHART_TOP + CHART_HEIGHT - barHeight;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; g.FillRectangle(new SolidBrush(ChartUtil.GetChartItemColor(i)), barOrigin.X, barOrigin.Y, barWidth, barHeight);<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">\n<p>&nbsp;&nbsp;&nbsp;&nbsp; g.DrawString(Mydata[i].Name, new Font(&quot;Tahoma&quot;, 3), Brushes.Black, new PointF(barOrigin.X-3, 277));<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp;&nbsp;&nbsp; barOrigin.X = barOrigin.X + (barWidth * 2);<br \/>&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; \/\/\u8bbe\u7f6e\u8fb9 <br \/>&nbsp;&nbsp;&nbsp; g.DrawLine(new Pen(Color.Black, 2), new Point(CHART_LEFT, CHART_TOP), new Point(CHART_LEFT, CHART_TOP + CHART_HEIGHT));<br \/>&nbsp;&nbsp;&nbsp; g.DrawLine(new Pen(Color.Black, 2), new Point(CHART_LEFT, CHART_TOP + CHART_HEIGHT), new Point(CHART_LEFT + CHART_WIDTH, CHART_TOP + CHART_HEIGHT));<br \/>&nbsp;&nbsp;&nbsp; \/\/\u753b\u56fe\u4f8b\u6846\u548c\u6587\u5b57<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp;&nbsp; \/\/g.DrawRectangle(Pens.Black, 200, 300, 199, 99);<br \/>&nbsp;&nbsp;&nbsp; \/\/g.DrawString(&quot;\u56fe\u8868\u8bf4\u660e&quot;, new Font(&quot;Tahoma&quot;, 12, FontStyle.Bold), Brushes.Black, new PointF(200, 300));<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp;&nbsp; g.DrawRectangle(new Pen(Color.Black, 1), 10, 290, 299, 110);<br \/>&nbsp;&nbsp;&nbsp; g.DrawString(&quot;\u56fe\u8868\u8bf4\u660e&quot;, new Font(&quot;Tahoma&quot;, 10, FontStyle.Bold), Brushes.Black, new PointF(11, 290));<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp;&nbsp; \/\/\u753b\u56fe\u4f8b <br \/>&nbsp;&nbsp;&nbsp; PointF boxOrigin = new PointF(10, 310);<br \/>&nbsp;&nbsp;&nbsp; PointF textOrigin = new PointF(35, 306);<br \/>&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; Mydata.Length; i++)<br \/>&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp; g.FillRectangle(new SolidBrush(ChartUtil.GetChartItemColor(i)), boxOrigin.X, boxOrigin.Y, 20, 10);<br \/>&nbsp;&nbsp;&nbsp;&nbsp; g.DrawRectangle(Pens.Black, boxOrigin.X, boxOrigin.Y, 2, 1);<br \/>&nbsp;&nbsp;&nbsp;&nbsp; g.DrawString(Mydata[i].Name.ToString() + &quot; - &quot; + Mydata[i].MValue.ToString(), new Font(&quot;Tahoma&quot;, 10), Brushes.Black, textOrigin);<br \/>&nbsp;&nbsp;&nbsp;&nbsp; if(i&lt;5)<br \/>&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boxOrigin.Y += 15;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textOrigin.Y += 15;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp; else if(i==5)<br \/>&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boxOrigin.X = 150;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boxOrigin.Y = 310;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textOrigin.X = 176;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textOrigin.Y = 306;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp;&nbsp; else<br \/>&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boxOrigin.Y += 15;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textOrigin.Y += 15;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; \/\/\u8f93\u51fa\u56fe\u5f62 <br \/>&nbsp;&nbsp;&nbsp; g.Dispose();<br \/><span style=\"color: red; line-height: 19px\">\/\/\u6b64\u5904\u5b58\u50a8\u8def\u5f84\u9700\u8981\u81ea\u5df1\u6539<\/span><br \/>\n<br \/>&nbsp;&nbsp; System.Drawing.Image MyImage=(System.Drawing.Image)bm;<br \/>&nbsp;&nbsp; string TruePath= System.Web.HttpContext.Current.Server.MapPath(&quot;~\/images&quot;);<br \/>&nbsp;&nbsp; string TrueName=DateTime.Now.ToString(&quot;yyyyMMddhhmmss&quot;)+DateTime.Now.Millisecond;<br \/>&nbsp;&nbsp; MyImage.Save(TruePath+&quot;<a href=\"file:\/\/%22+truename+%22.jpg\/\" style=\"color: rgb(67,113,166)\">\\\\&quot;+TrueName+&quot;.jpg<\/a><br \/>\n&quot;, System.Drawing.Imaging.ImageFormat.Gif);<br \/>&nbsp;&nbsp; return &quot;~\/images\/&quot;+TrueName+&quot;.jpg&quot;;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">}<br \/>}<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">\/\/\/ &lt;summary&gt;<br \/>\/\/\/ \u9009\u62e9\u989c\u8272<br \/>\/\/\/ &lt;\/summary&gt;<br \/>public class ChartUtil<br \/>{<br \/>public ChartUtil()<br \/>{<br \/>}<br \/>public static Color GetChartItemColor(int itemIndex)<br \/>{<br \/>&nbsp;&nbsp; Color selectedColor;<br \/>&nbsp;&nbsp; switch (itemIndex)<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; case 0:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.AliceBlue;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 1:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.Red;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 2:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.Yellow;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 3:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.AntiqueWhite;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 4:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.Aqua;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 5:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.Aquamarine;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 6:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.Azure;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 7:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.Beige;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 8:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.Black;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 9:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.Brown;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 10:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.Coral;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 11:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.DarkCyan;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; case 12:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.DarkOrange;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp;&nbsp; default:<br \/>&nbsp;&nbsp;&nbsp;&nbsp; selectedColor = Color.DarkViolet;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; return selectedColor;<br \/>}<br \/>}<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">\/\/\/ &lt;summary&gt;<br \/>\/\/\/ \u997c\u72b6\u56fe\u7684\u6570\u636e\u5bf9\u8c61<br \/>\/\/\/ &lt;\/summary&gt;<br \/>public class PieChartValue<br \/>{<br \/>public PieChartValue()<br \/>{<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">}<br \/>public PieChartValue(string MyName, int Myvalue)<br \/>{<br \/>&nbsp;&nbsp; Name = MyName;<br \/>&nbsp;&nbsp; MValue = Myvalue;<br \/>}<br \/>private string name;<br \/>public string Name<br \/>{<br \/>&nbsp;&nbsp; get<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; return name;<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; set<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; name = value;<br \/>&nbsp;&nbsp; }<br \/>}<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">private int mvalue;<br \/>public int MValue<br \/>{<br \/>&nbsp;&nbsp; get<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; return mvalue;<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; set<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; mvalue = value;<br \/>&nbsp;&nbsp; }<br \/>}<br \/>}<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">\/\/\/ &lt;summary&gt;<br \/>\/\/\/ \u67f1\u72b6\u56fe\u7684\u6570\u636e\u5bf9\u8c61<br \/>\/\/\/ &lt;\/summary&gt;<br \/>public class BarChartValue<br \/>{<br \/>public BarChartValue()<br \/>{<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">}<br \/>public BarChartValue(string MyName, int Myvalue)<br \/>{<br \/>&nbsp;&nbsp; Name = MyName;<br \/>&nbsp;&nbsp; MValue = Myvalue;<br \/>}<br \/>private string name;<br \/>public string Name<br \/>{<br \/>&nbsp;&nbsp; get<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; return name;<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; set<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; name = value;<br \/>&nbsp;&nbsp; }<br \/>}<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">private int mvalue;<br \/>public int MValue<br \/>{<br \/>&nbsp;&nbsp; get<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; return mvalue;<br \/>&nbsp;&nbsp; }<br \/>&nbsp;&nbsp; set<br \/>&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp; mvalue = value;<br \/>&nbsp;&nbsp; }<br \/>}<br \/>}<br \/>}<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">\u7528\u6cd5<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp; #region \u751f\u6210\u67f1\u72b6\u56fe<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp; MyImage MyMyImage = new MyImage();<br \/>&nbsp;&nbsp; BarChartValue[] BarChartValue ={<span class=\"Apple-converted-space\"> <\/span><br \/>\n<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new BarChartValue(&quot;\u7b2c1\u4e2a\u6708&quot;,5),<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new BarChartValue(&quot;\u7b2c2\u4e2a\u6708&quot;,2),<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new BarChartValue(&quot;\u7b2c3\u4e2a\u6708&quot;,3),<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new BarChartValue(&quot;\u7b2c4\u4e2a\u6708&quot;,4),<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new BarChartValue(&quot;\u7b2c5\u4e2a\u6708&quot;,5),<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new BarChartValue(&quot;\u7b2c6\u4e2a\u6708&quot;,6),<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new BarChartValue(&quot;\u7b2c7\u4e2a\u6708&quot;,7),<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new BarChartValue(&quot;\u7b2c8\u4e2a\u6708&quot;,8),<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new BarChartValue(&quot;\u7b2c9\u4e2a\u6708&quot;,9)<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br \/>&nbsp;&nbsp; Image1.ImageUrl = MyMyImage.Render(&quot;\u5168\u5e74\u7edf\u8ba1&quot;, &quot;98\u5e74&quot;, 1000, 1000, BarChartValue);<br \/>&nbsp;&nbsp; #endregion<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp; #region \u751f\u6210\u997c\u72b6\u56fe<br \/>&nbsp;&nbsp; PieChartValue[] PieChartValue ={<span class=\"Apple-converted-space\"> <\/span><br \/>\n<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new PieChartValue(&quot;\u7b2c\u4e00\u4e2a\u4ed3\u5e93&quot;,1),<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new PieChartValue(&quot;\u7b2c\u4e00\u4e2a\u4ed3\u5e93&quot;,2)<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;&nbsp; Image2.ImageUrl = MyMyImage.Render(&quot;\u4ed3\u5e93\u7edf\u8ba1\u997c\u72b6\u56fe&quot;, &quot;\u5c0f\u4ed3\u5e93&quot;, 500, 500, PieChartValue);<br \/>&nbsp;&nbsp; #endregion<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\"><span class=\"Apple-style-span\" style=\"word-spacing: 0px; font: 16px simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; widows: 2; orphans: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"><span class=\"Apple-style-span\" style=\"font-size: 13px; color: rgb(75,75,75); line-height: 20px\">using System;<br \/>using System.IO;\/\/\u7528\u4e8e\u6587\u4ef6\u5b58\u53d6 <\/span><br \/>using System.Data;\/\/\u7528\u4e8e\u6570\u636e\u8bbf\u95ee <\/span><br \/>using System.Drawing;\/\/\u63d0\u4f9b\u753bGDI+\u56fe\u5f62\u7684\u57fa\u672c\u529f\u80fd <br \/>using System.Drawing.Text;\/\/\u63d0\u4f9b\u753bGDI+\u56fe\u5f62\u7684\u9ad8\u7ea7\u529f\u80fd <br \/>using System.Drawing.Drawing2D;\/\/\u63d0\u4f9b\u753b\u9ad8\u7ea7\u4e8c\u7ef4\uff0c\u77e2\u91cf\u56fe\u5f62\u529f\u80fd <br \/>using System.Drawing.Imaging;\/\/\u63d0\u4f9b\u753bGDI+\u56fe\u5f62\u7684\u9ad8\u7ea7\u529f\u80fd <br \/>namespace lc.laili.Web.Code<br \/>{<br \/>\/\/\/ &lt;summary&gt;<br \/>\/\/\/ MyImage \u7684\u6458\u8981\u8bf4\u660e\u3002<br \/>\/\/\/ &lt;\/summary&gt;<br \/>public class MyImage<br \/>{<br \/>public MyImage()<br \/>{<br \/>&nbsp;&nbsp; \/\/<br \/>&nbsp;&nbsp; \/\/ TODO: \u5728\u6b64\u5904\u6dfb\u52a0\u6784\u9020\u51fd\u6570\u903b\u8f91<br \/>&nbsp;&nbsp; \/\/<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">}<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">&nbsp;<\/p>\n<p style=\"margin: 0px auto 10px; text-indent: 0px\">\/\/\/ &lt;summary&gt;<br \/>\/\/\/ \u6570\u636e\u6e90\u662fPieChartValue\u5bf9\u8c61\u7684\u997c\u72b6\u56fe<br \/>\/\/\/ &lt;\/summar...<\/p>\n<p> <a href=\"https:\/\/www.xiaobo.li\/notes\/archives\/126\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[273],"tags":[16,47],"class_list":["post-126","post","type-post","status-publish","format-standard","hentry","category-article","tag-C","tag-GDI"],"_links":{"self":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":0,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}