protected void Page_Load(object sender, EventArgs e) { Chart1.BackColor = Color.Moccasin; Chart1.BackGradientStyle = GradientStyle.DiagonalRight; Chart1.BorderlineDashStyle = ChartDashStyle.Solid; Chart1.BorderlineColor = Color.Gray; Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss; DateTime dt = Convert.ToDateTime(DropDownList1.SelectedValue); // forma the chart area Chart1.ChartAreas[0].BackColor = Color.Wheat; // add and format the title Chart1.Titles.Add("年度审核情况表"); // Chart1.Titles[0].Font = new Font("Utopia", 14, FontStyle.Bold); Chart1.Series.Add(new Series("Pie") { ChartType = SeriesChartType.Pie, ShadowOffset = 2 }); DtCms.BLL.Activity activity = new DtCms.BLL.Activity(); Chart1.Series[0].Label = "#VALX \n\n #PERCENT{P}";//显示百分比和说明 Chart1.Series[0].LegendText = "#VALX"; int a = activity.GetCountMode("审核通过", dt); int b = activity.GetCountMode("不批准", dt); int c = activity.GetCountMode("退回修改", dt); int d = activity.GetCountMode("未审核", dt); int f = activity.GetCountMode("再次提交", dt); double[] yValues = { a, b, c, d, f }; string[] xValues = { "审核通过", "不批准", "退回修改", "未审核", "再次提交" }; //饼状图的标签方位 Chart1.Series[0]["PieLabelStyle"] = "Outside"; Chart1.Series[0]["PieLineColor"] = "Black"; Chart1.Series[0].Points.DataBindXY(xValues, yValues); //每个部分开花 foreach (DataPoint point in Chart1.Series[0].Points) { point["Exploded"] = "true"; } }
protected void Page_Load(object sender, EventArgs e) { DtCms.BLL.Activity activity = new DtCms.BLL.Activity(); int[] icount = new int[4]; string[] irange = new string[4]; icount[0] = activity.GetCountMode("审核通过"); icount[1] = activity.GetCountMode("不批准"); icount[2] = activity.GetCountMode("退回修改"); icount[3] = activity.GetCountMode("未审核"); Bitmap bm = new Bitmap(700, 300); Graphics g; g = Graphics.FromImage(bm); //由此Bitmap实例创建Graphic实例 g.Clear(Color.White); g.DrawString("活动审核情况", new Font("微软雅黑", 16), Brushes.Black, new Point(150, 5)); irange[0] = "审核通过"; irange[1] = "不批准"; irange[2] = "退回修改"; irange[3] = "未审核"; Point myRec = new Point(515, 34); Point myDec = new Point(540, 30); Point myTxt = new Point(628, 30); g.DrawString("单位:个", new Font("微软雅黑", 9), Brushes.Black, new Point(555, 12)); for (int i = 0; i < 4; i++) { g.FillRectangle(new SolidBrush(GetColor(i)), myRec.X, myRec.Y, 20, 10); //填充小方块 g.DrawRectangle(Pens.Black, myRec.X, myRec.Y, 20, 10); //绘制小方块 g.DrawString(irange[i].ToString() + "", new Font("微软雅黑", 9), Brushes.Black, myDec); //绘制小方块右边的文字 g.DrawString(icount[i].ToString(), new Font("微软雅黑", 9), Brushes.Black, myTxt); myRec.Y += 15; myDec.Y += 15; myTxt.Y += 15; } //从数据库中得到的数值大小,绘制扇型,并以相应色彩填充扇型 int iTatal = 0; float fCurrentAngle = 0; float fStartAngle = 0; for (int i = 0; i < icount.Length; i++) { iTatal = iTatal + icount[i]; } for (int i = 0; i < icount.Length; i++) { //以下代码是获得要绘制扇型的开始角度 if (i == icount.Length - 1) { fCurrentAngle = 360 - fStartAngle; } else { int iTemp = icount[i]; fCurrentAngle = (iTemp * 360) / iTatal; } g.FillPie(new SolidBrush(GetColor(i)), 100, 40, 250, 250, fStartAngle, fCurrentAngle); fStartAngle += fCurrentAngle; } Pen p = new Pen(Color.Black, 2); g.DrawRectangle(p, 1, 1, 698, 298); // filestream fs = new filestream(Pie.jpg, filemode.create); // System.Drawing.Image originalImage = System.Drawing.Bitmap.FromStream(file.InputStream); // pbphoto.image.save(fs, imageformat.jpeg); bm.Save(@"D:\gradution_file\Dtcms.Web\Admin\Images\Pie.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); // bm.Save(Response.OutputStream, ImageFormat.Jpeg); g.Dispose(); }