//画图例框和文字 g.DrawRectangle(new Pen(Color.Black,1),200,300,199,99); g.DrawString("图表说明",new Font("Tahoma",12,FontStyle.Bold),Brushes.Black,new PointF(200,300)); //画图例 PointF boxOrigin = new PointF(210,330); PointF textOrigin = new PointF(235,326); for(int i=0;i { g.FillRectangle(new SolidBrush(ChartUtil.GetChartItemColor(i)),boxOrigin.X,boxOrigin.Y,20,10); g.DrawRectangle(Pens.Black,boxOrigin.X,boxOrigin.Y,20,10); g.DrawString(dt.Rows[i][1].ToString() + " - " + dt.Rows[i][0].ToString(),new Font("Tahoma",10),Brushes.Black,textOrigin); boxOrigin.Y += 15; textOrigin.Y += 15; } //输出图形 g.Dispose(); return bm; } catch { return bm; } } } public class ChartUtil { public ChartUtil() { } public static Color GetChartItemColor(int itemIndex) { Color selectedColor; switch(itemIndex) { case 0: selectedColor = Color.Blue; break; case 1: selectedColor = Color.Red; break; case 2: selectedColor = Color.Yellow; break; case 3: selectedColor = Color.Purple; break; default: selectedColor = Color.Green; break; } return selectedColor; |