/// <summary> /// 画报表标题 /// </summary> private void DrawChartName() { string chartName = string.IsNullOrWhiteSpace(this.ChartName) ? "报表" : this.ChartName; chartNameRectangle = new TRectangle(this.Width * 0.5F - chartName.Length * 30 / 2, 5, chartName.Length * 30, 31); graphics.DrawString(chartName, new Font("Arial", 20, FontStyle.Regular), Brushes.Black, chartNameRectangle.X, chartNameRectangle.Y); }
/// <summary> /// 画提示框 /// </summary> public void DrawTipRectangle(Graphics graphics) { StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; Pen tipPen = new Pen(this.Color, 1); graphics.DrawLine(tipPen, X, Y, X, Y - 6); this.Width = Value.Length * 8; this.Rectangle = new TRectangle(X - this.Width / 2, Y - 6 - this.Height, this.Width, this.Height); graphics.DrawRectangle(tipPen, this.Rectangle.X, this.Rectangle.Y, this.Rectangle.Width, this.Rectangle.Height); //画白色背景 graphics.FillRectangle(new SolidBrush(Color.White), this.Rectangle.X + 1, this.Rectangle.Y + 1, this.Rectangle.Width - 2, this.Rectangle.Height - 2); graphics.DrawString(this.Value, new Font("宋体", 9, FontStyle.Regular), new SolidBrush(this.Color), new RectangleF(this.Rectangle.X, this.Rectangle.Y, this.Rectangle.Width, this.Rectangle.Height), stringFormat); }
/// <summary> /// 画图例 /// </summary> private void DrawLegend() { //序列名称最长的长度 var seriesNameMaxLength = series.Select(s => s.Name).Max(m => m.Length); int seriesCount = series.Count; int steps = 0; int colorIndex = 0; float seriesWidth = 20; float seriesHeight = 14; //图例原点坐标 legendRectangle = new TRectangle { X = this.Width - 10 - seriesWidth - 2 - 12 * seriesNameMaxLength, Y = chartNameRectangle.Y + chartNameRectangle.Height + 5 }; //画具体的series foreach (var item in series) { if (item.SeriesColor == Color.Empty) { Color itemColor = Color.Empty; //项目颜色 if (colorIndex > itemColors.Length) { itemColor = itemColors[colorIndex - itemColors.Length]; } { itemColor = itemColors[colorIndex]; } item.SeriesColor = itemColor; colorIndex++; } TRectangle seriesRect = new TRectangle(legendRectangle.X + 5, legendRectangle.Y + seriesHeight * steps + 4 * (steps + 1), seriesWidth, seriesHeight); graphics.FillRectangle(new SolidBrush(item.SeriesColor), seriesRect); item.LegendRectangle = seriesRect; //画内部阴影矩形 graphics.DrawRectangle(rectInsidePen, seriesRect.X, seriesRect.Y, seriesRect.Width, seriesRect.Height); graphics.DrawString(item.Name, new Font("宋体", 10, FontStyle.Regular), Brushes.Black, seriesRect.X + seriesWidth, seriesRect.Y); steps++; } legendRectangle.Width = this.Width - 5 - legendRectangle.X; legendRectangle.Height = seriesHeight * seriesCount + 4 * seriesCount + 4; graphics.DrawRectangle(legendPen, legendRectangle); }
/// <summary> /// 画X、Y轴 /// </summary> private void DrawXY() { Pen XYpen = new Pen(Color.FromArgb(125, 94, 32), 1); //画X轴 graphics.DrawLine(XYpen, intersection.X, intersection.Y, this.Width - legendRectangle.Width - 20, intersection.Y); XLength = this.Width - legendRectangle.Width - 20 - intersection.X; //画Y轴 graphics.DrawLine(XYpen, intersection.X, intersection.Y, intersection.X, this.legendRectangle.Y); YLength = intersection.Y - this.legendRectangle.Y; //画边界线 graphics.DrawLine(legendPen, intersection.X, intersection.Y - YLength, intersection.X + XLength, intersection.Y - YLength); graphics.DrawLine(legendPen, intersection.X + XLength, intersection.Y - YLength, intersection.X + XLength, intersection.Y); XYRectangle = new TRectangle(intersection.X + 1, this.legendRectangle.Y + 1, XLength - 2, YLength - 2); //填充背景色 graphics.FillRectangle(new LinearGradientBrush(new PointF(0, 0), new PointF(XYRectangle.X + XYRectangle.Width, XYRectangle.Y + XYRectangle.Height), Color.FromArgb(249, 241, 228), Color.FromArgb(249, 241, 228)), XYRectangle); }
/// <summary> /// 画矩形 /// </summary> /// <param name="graphics">绘图图面</param> /// <param name="pen">画笔</param> /// <param name="x">X坐标</param> /// <param name="y">Y坐标</param> /// <param name="width">宽度</param> /// <param name="height">高度</param> public static void FillRectangle(this Graphics graphics, Brush brush, TRectangle rectangle) { graphics.FillRectangle(brush, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); }
/// <summary> /// 画矩形 /// </summary> /// <param name="graphics">绘图图面</param> /// <param name="pen">画笔</param> /// <param name="x">X坐标</param> /// <param name="y">Y坐标</param> /// <param name="width">宽度</param> /// <param name="height">高度</param> public static void DrawRectangle(this Graphics graphics, Pen pen, TRectangle rectangle) { graphics.DrawRectangle(pen, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); }