public void drawLegendnote(Graphics g, Pen linePen, Brush lineBrush, Brush TextBrush, Brush DataBrush, Font FontText, Font FontData) { if (CoordinateModels == null) { return; } //设定默认的初始颜色 if (CoordinateModels != null && CoordinateModels.Count > 0) { ModelColor = CoordinateModels[0].ModelColor; } foreach (DataModel item in CoordinateModels) { if (IsGroup(item)) { GroupData = new List <DataModel>(); GroupData.Add(item); } } List <Rectangle> position = GetAllRectangle(); //圆角矩形标签绘制 for (int i = 0; i < position.Count; i++) { ReportViewUtils.drawString(g, LocationModel.Location_Left_Left, TitlesName[i], FontData, TextBrush, position[i].X + LegendNoteWidth, position[i].Y - LegendNoteHeight, (Width - EViewWidth) / 2, LegendNoteHeight + padding); GraphicsPath path = ReportViewUtils.CreateRoundedRectanglePath(position[i], LegendNoteHeight / 2); Brush bbsh = new SolidBrush(ALLGroup[0][i].ModelColor); g.FillPath(bbsh, path); bbsh.Dispose(); path.Dispose(); } // 绘制围绕点旋转的文本 StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; for (int i = 0; i < ALLGroup.Count; i++) { DrawRoateText.DrawString(g, ALLGroup[i][0].mainText, LableFont, TextBrush, new PointF(ALLGroup[i][0].Area.left + MultiPadding / 2, CoordinateStartY + padding), format, TextRotate); } ALLGroup = new List <List <DataModel> >(); GroupData = new List <DataModel>(); }
public override void DrawSelfDefine(System.Drawing.Graphics g, System.Drawing.Pen linePen, System.Drawing.Brush lineBrush, System.Drawing.Brush TextBrush, System.Drawing.Brush DataBrush, System.Drawing.Font FontText, System.Drawing.Font FontData) { linePen.Width = 1.0f; Font LableFont = new Font("Arial", LableSize); Font AllSumFont = new Font("Arial", AllSumSize); //绘制横坐标和标题 ReportViewUtils.drawString(g, Title, FontText, TextBrush, EStartX, EStartY, EViewWidth, TopPadding); g.DrawLine(linePen, CoordinateStartX, CoordinateStartY, CoordinateStartX + CoordinateWidth, CoordinateStartY); if (!IsEnableGridLine) { g.DrawLine(linePen, CoordinateStartX + CoordinateWidth, CoordinateStartY, CoordinateStartX + CoordinateWidth - 6, CoordinateStartY + 3); g.DrawLine(linePen, CoordinateStartX + CoordinateWidth, CoordinateStartY, CoordinateStartX + CoordinateWidth - 6, CoordinateStartY - 3); } // 绘制围绕点旋转的文本 StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; //绘制标签 DrawRoateText.DrawString(g, LableX, LableFont, TextBrush, new PointF(CoordinateStartX + CoordinateWidth + padding, CoordinateStartY + padding), format, TextRotate); //数据源长度 int dataLength = 0; if (CoordinateModels != null) { dataLength = CoordinateModels.Count / (ModelCount); } Point[] listPoint = new Point[dataLength]; //绘制刻度 float per_X = 0; if (IsEnableGridLine) { per_X = (CoordinateWidth * 1.0f) / Count_X; } else { per_X = (CoordinateWidth - padding) * 1.0f / Count_X; } for (int i = 0; i < Count_X + 1; i++) { //绘制刻度 int x = (int)(CoordinateStartX + i * per_X); if (IsEnableGridLine) { linePen.Color = Color.FromArgb(30, LineColor.R, LineColor.G, LineColor.B); g.DrawLine(linePen, x, CoordinateStartY, x, CoordinateStartY - CoordinateHeight); } else { g.DrawLine(linePen, x, CoordinateStartY, x, CoordinateStartY - padding / 10); } if (dataLength > i) { listPoint[i] = new Point(x, 0); } //绘制刻度值 if (IsShowX_Scale) { if (dataLength > i) { if (CoordinateDataModelBean != null) { DrawRoateText.DrawString(g, CoordinateDataModelBean.X_Data[i], LableFont, TextBrush, new PointF(CoordinateStartX + i * per_X, CoordinateStartY + padding), format, TextRotate); } } } } linePen.Color = LineColor; //如果自动刷新时间, 则会刷新最大值, 从而刷新Y轴 if (isAutoUpdateData) { if (CoordinateDataModelBean != null) { if (CoordinateDataModelBean.Y_Data != null) { MaxNum = ReportViewUtils.getMaxNumFromData(CoordinateDataModelBean.Y_Data); } } } //绘制Y轴 g.DrawLine(linePen, CoordinateStartX, CoordinateStartY, CoordinateStartX, CoordinateStartY - CoordinateHeight); if (!IsEnableGridLine) { g.DrawLine(linePen, CoordinateStartX + 3, CoordinateStartY - CoordinateHeight + 6, CoordinateStartX, CoordinateStartY - CoordinateHeight); g.DrawLine(linePen, CoordinateStartX - 3, CoordinateStartY - CoordinateHeight + 6, CoordinateStartX, CoordinateStartY - CoordinateHeight); } //绘制标签 int lableLength = CoordinateDataModelBean.Lable_Y.Length; ReportViewUtils.drawString(g, LocationModel.Location_Right_Right, LableY, LableFont, TextBrush, EStartX, CoordinateStartY - CoordinateHeight - padding, LeftPadding - 10, padding); //g.DrawString(LableY, LableFont, TextBrush, (padding - lableLength * lableSize) / 2 + startX, startY + topPadding); //对应到坐标上 //规定Y轴刻度值 float perNum = MaxNum / Count_Y; //规定Y轴刻度 float per_Y = 0; if (IsEnableGridLine) { per_Y = (CoordinateHeight) * 1.0f / Count_Y; } else { per_Y = (CoordinateHeight - padding) * 1.0f / Count_Y; } //绘制刻度值和刻度 linePen.Color = Color.FromArgb(30, LineColor.R, LineColor.G, LineColor.B); for (int i = 0; i < Count_Y + 1; i++) { if (IsShowY_Scale) { ReportViewUtils.drawString(g, LocationModel.Location_Right_Right, perNum * i + "", LableFont, TextBrush, EStartX, CoordinateStartY - i * per_Y - padding / 2, LeftPadding - 10, padding); //g.DrawString(perNum * i + "", LableFont, TextBrush, (padding - lableSize * 3) / 2 + startX, height - padding - i * per_Y - lableSize - bottomPadding); } int y = (int)(CoordinateStartY - i * per_Y); g.DrawLine(linePen, CoordinateStartX, y, CoordinateStartX + CoordinateWidth, y); } linePen.Color = LineColor; for (int j = 0; j < ModelCount; j++) { linePen.Color = CoordinateDataModelBean.CoordinateModelList[dataLength * j].ModelColor; //计算数据中的点对应到坐标的点 bool isMouseIn = false; for (int i = 0; i < dataLength; i++) { float dataY = CoordinateDataModelBean.Y_Data[i + dataLength * j]; //把数据对应到实际的坐标 int posY = (int)(CoordinateStartY - dataY * per_Y / perNum); listPoint[i].Y = posY; //重新定位数据模型的坐标 isMouseIn = adapter.DataList[i + dataLength * j].Area.IsMouseIn; adapter.DataList[i + dataLength * j].Area = ReLoadAreaPosition(listPoint[i].X, listPoint[i].Y, (int)per_X, (int)per_Y); //adapter.DataList[i].Area = new AreaPositionRect(listPoint[i].X, listPoint[i].Y, listPoint[i].X, listPoint[i].Y); adapter.DataList[i + dataLength * j].Area.IsMouseIn = isMouseIn; } //绘制曲线 if (IsDrawCurve) { if (listPoint.Length > 0) { g.DrawCurve(linePen, listPoint, Tension); } } if (IsFillPathCurve) { Point[] point2 = new Point[4]; if (listPoint.Length > 0) { GraphicsPath path = null; point2[0].X = listPoint[dataLength - 1].X; point2[0].Y = listPoint[dataLength - 1].Y; point2[1].X = listPoint[dataLength - 1].X; point2[1].Y = CoordinateStartY; point2[2].X = CoordinateStartX; point2[2].Y = CoordinateStartY; point2[3].X = CoordinateStartX; point2[3].Y = listPoint[0].Y; path = CreatePath(listPoint, point2); Brush fillBrush = new SolidBrush(Color.FromArgb(FillBrushAlpha, linePen.Color.R, linePen.Color.G, linePen.Color.B)); g.FillPath(fillBrush, path); fillBrush.Dispose(); path.Dispose(); } } if (IsShowLegendnote) { CalculateAllNum(dataLength, j); ReportViewUtils.drawString(g, LocationModel.Location_Left_Left, Titles[j] + allNum + LableAllNum, LableFont, TextBrush, CoordinateStartX + CoordinateWidth + ((Width - EViewWidth) / 4 + LegendNoteWidth + 10), CoordinateStartY - CoordinateHeight + (LegendNoteHeight + padding) * j, (Width - EViewWidth) / 2, LegendNoteHeight + padding); Rectangle rect = new Rectangle(CoordinateStartX + CoordinateWidth + ((Width - EViewWidth) / 2 - LegendNoteWidth) / 2, CoordinateStartY - CoordinateHeight + (LegendNoteHeight + padding) * (j) + padding / 2, LegendNoteWidth, LegendNoteHeight); GraphicsPath path = ReportViewUtils.CreateRoundedRectanglePath(rect, LegendNoteHeight / 2); Brush bbsh = new SolidBrush(linePen.Color); g.FillPath(bbsh, path); bbsh.Dispose(); path.Dispose(); } //drawAllsumText(g, AllSumFont, TextBrush, CoordinateStartX, CoordinateStartY, CoordinateWidth, CoordinateHeight); } AllSumFont.Dispose(); LableFont.Dispose(); }
public override void DrawSelfDefine(System.Drawing.Graphics g, System.Drawing.Pen linePen, System.Drawing.Brush lineBrush, System.Drawing.Brush TextBrush, System.Drawing.Brush DataBrush, System.Drawing.Font FontText, System.Drawing.Font FontData) { linePen.Width = 1.0f; Font LableFont = null; if (IsLableFontBold) { LableFont = new Font("幼圆", LableSize, FontStyle.Bold); } else { LableFont = new Font("幼圆", LableSize); } Font AllSumFont = new Font("Arial", AllSumSize); //数据源长度 int dataLength = 0; if (CoordinateModels != null) { dataLength = CoordinateModels.Count; } Point[] listPoint = new Point[dataLength]; if (IsDrawTitle) { ReportViewUtils.drawString(g, Title, FontText, TextBrush, EStartX, EStartY, EViewWidth, TopPadding); } g.DrawLine(linePen, CoordinateStartX, CoordinateStartY, CoordinateStartX + CoordinateWidth, CoordinateStartY); if (!IsEnableGridLine) { if (IsEnableArrow) { g.DrawLine(linePen, CoordinateStartX + CoordinateWidth, CoordinateStartY, CoordinateStartX + CoordinateWidth - 6, CoordinateStartY + 3); g.DrawLine(linePen, CoordinateStartX + CoordinateWidth, CoordinateStartY, CoordinateStartX + CoordinateWidth - 6, CoordinateStartY - 3); } } // 绘制围绕点旋转的文本 StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; //绘制标签 DrawRoateText.DrawString(g, LableX, LableFont, TextBrush, new PointF(CoordinateStartX + CoordinateWidth + padding, CoordinateStartY + padding), format, TextRotate); //绘制刻度 float per_X = 0; if (IsEnableGridLine) { per_X = (CoordinateWidth * 1.0f) / Count_X; } else { per_X = (CoordinateWidth - padding) * 1.0f / Count_X; } for (int i = 0; i < Count_X + 1; i++) { //绘制刻度 int x = (int)(CoordinateStartX + i * per_X); if (IsEnableGridLine) { linePen.Color = Color.FromArgb(30, LineColor.R, LineColor.G, LineColor.B); g.DrawLine(linePen, x, CoordinateStartY, x, CoordinateStartY - CoordinateHeight); } else { g.DrawLine(linePen, x, CoordinateStartY, x, CoordinateStartY - padding / 10); } if (dataLength > i) { listPoint[i] = new Point(x, 0); } //绘制刻度值 if (IsShowX_Scale) { if (dataLength > i) { if (CoordinateDataModelBean != null) { if (IsRectAngle) { if (ConformCount == 0) { DrawRoateText.DrawString(g, CoordinateDataModelBean.X_Data[i], LableFont, TextBrush, new PointF(CoordinateStartX + i * per_X + per_X / 4, CoordinateStartY + padding), format, TextRotate); } else { DrawRoateText.DrawString(g, CoordinateDataModelBean.X_Data[i], LableFont, TextBrush, new PointF(CoordinateStartX + i * per_X + (ConformCount - 1) * 1.0f / 2 * per_X + per_X / 4, CoordinateStartY + padding), format, TextRotate); } } else { DrawRoateText.DrawString(g, CoordinateDataModelBean.X_Data[i], LableFont, TextBrush, new PointF(CoordinateStartX + i * per_X, CoordinateStartY + padding), format, TextRotate); } } } } } linePen.Color = LineColor; //如果自动刷新时间, 则会刷新最大值, 从而刷新Y轴 if (isAutoUpdateData) { if (CoordinateDataModelBean != null) { if (CoordinateDataModelBean.Y_Data != null) { MaxNum = ReportViewUtils.getMaxNumFromData(CoordinateDataModelBean.Y_Data); } } } //绘制Y轴 g.DrawLine(linePen, CoordinateStartX, CoordinateStartY, CoordinateStartX, CoordinateStartY - CoordinateHeight); if (!IsEnableGridLine) { if (IsEnableArrow) { g.DrawLine(linePen, CoordinateStartX + 3, CoordinateStartY - CoordinateHeight + 6, CoordinateStartX, CoordinateStartY - CoordinateHeight); g.DrawLine(linePen, CoordinateStartX - 3, CoordinateStartY - CoordinateHeight + 6, CoordinateStartX, CoordinateStartY - CoordinateHeight); } } //绘制标签 int lableLength = CoordinateDataModelBean.Lable_Y.Length; ReportViewUtils.drawString(g, LocationModel.Location_Right_Right + padding, LableY, LableFont, TextBrush, EStartX, CoordinateStartY - CoordinateHeight - padding, LeftPadding - 10, padding); //g.DrawString(LableY, LableFont, TextBrush, (padding - lableLength * lableSize) / 2 + startX, startY + topPadding); //对应到坐标上 //规定Y轴刻度值 float perNum = MaxNum / Count_Y; //规定Y轴刻度 float per_Y = 0; if (IsEnableGridLine) { per_Y = (CoordinateHeight) * 1.0f / Count_Y; } else { per_Y = (CoordinateHeight - padding) * 1.0f / Count_Y; } //绘制刻度值和刻度 linePen.Color = Color.FromArgb(30, LineColor.R, LineColor.G, LineColor.B); for (int i = 0; i < Count_Y + 1; i++) { if (IsShowY_Scale) { ReportViewUtils.drawString(g, LocationModel.Location_Right_Right, (int)perNum * i + "", LableFont, TextBrush, EStartX, CoordinateStartY - i * per_Y - padding / 2, LeftPadding - 10, padding); //g.DrawString(perNum * i + "", LableFont, TextBrush, (padding - lableSize * 3) / 2 + startX, height - padding - i * per_Y - lableSize - bottomPadding); } int y = (int)(CoordinateStartY - i * per_Y); g.DrawLine(linePen, CoordinateStartX, y, CoordinateStartX + CoordinateWidth, y); } linePen.Color = LineColor; //计算数据中的点对应到坐标的点 bool isMouseIn = false; for (int i = 0; i < dataLength; i++) { float dataY = CoordinateDataModelBean.Y_Data[i]; //把数据对应到实际的坐标 int posY = (int)(CoordinateStartY - dataY * per_Y / perNum); listPoint[i].Y = posY; //重新定位数据模型的坐标 isMouseIn = adapter.DataList[i].Area.IsMouseIn; adapter.DataList[i].Area = ReLoadAreaPosition(listPoint[i].X, listPoint[i].Y, (int)per_X, (int)per_Y); //adapter.DataList[i].Area = new AreaPositionRect(listPoint[i].X, listPoint[i].Y, listPoint[i].X, listPoint[i].Y); adapter.DataList[i].Area.IsMouseIn = isMouseIn; } //绘制曲线 if (IsDrawCurve) { if (listPoint.Length > 0) { g.DrawCurve(linePen, listPoint, Tension); } } if (IsFillPathCurve) { Point[] point2 = new Point[4]; if (listPoint.Length > 0) { GraphicsPath path = null; point2[0].X = listPoint[dataLength - 1].X; point2[0].Y = listPoint[dataLength - 1].Y; point2[1].X = listPoint[dataLength - 1].X; point2[1].Y = CoordinateStartY; point2[2].X = CoordinateStartX; point2[2].Y = CoordinateStartY; point2[3].X = CoordinateStartX; point2[3].Y = listPoint[0].Y; path = CreatePath(listPoint, point2); Brush fillBrush = new SolidBrush(Color.FromArgb(FillBrushAlpha, LineColor.R, LineColor.G, LineColor.B)); g.FillPath(fillBrush, path); fillBrush.Dispose(); path.Dispose(); } } drawAllsumText(g, AllSumFont, TextBrush, CoordinateStartX, CoordinateStartY, CoordinateWidth, CoordinateHeight); ////绘制点 //for (int i = 0; i < dataLength; i++) //{ // Point item = listPoint[i]; // if (IsDrawDetailData) // { // //ReportViewUtils.drawString(g, LocationModel.Location_Right_Right, CoordinateDataModelBean.Y_Data[i] + "", FontData, DataBrush, StartX, StartY, LeftPadding, padding); // g.DrawString(CoordinateDataModelBean.Y_Data[i] + "", FontData, DataBrush, (item.X), item.Y - 2 * DataSize); // } // g.FillEllipse(TextBrush, item.X - 2, item.Y - 2, 4, 4); //} AllSumFont.Dispose(); LableFont.Dispose(); }