public void AddChart(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d) { switch (ChartType) { case ChartTypeEnum.Line: AddLine(g, ds, cs); break; case ChartTypeEnum.Mesh: AddMesh(g, ds, cs); AddColorBar(g, ds, cs, cs2d); break; case ChartTypeEnum.MeshZ: AddMeshZ(g, ds, cs); AddColorBar(g, ds, cs, cs2d); break; case ChartTypeEnum.Waterfall: AddWaterfall(g, ds, cs); AddColorBar(g, ds, cs, cs2d); break; case ChartTypeEnum.Surface: AddSurface(g, ds, cs, cs2d); AddColorBar(g, ds, cs, cs2d); break; } }
/// <summary> /// Copy constructor /// </summary> /// public ChartStyle2D(ChartStyle2D rhs) { _mchartArea = rhs._mchartArea; _mchartBackColor = rhs._mchartBackColor; _mchartBorderColor = rhs._mchartBorderColor; _mplotBackColor = rhs._mchartBorderColor; _mplotBorderColor = rhs._mchartBorderColor; }
/// <summary> /// 在图形右侧创建图例柱状图,标识颜色代表的数据值 /// </summary> /// <param name="g"></param> /// <param name="ds"></param> /// <param name="cs"></param> /// <param name="cs2d"></param> public void AddColorBar(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d) { if (cs.IsColorBar && IsColorMap) { Pen aPen = new Pen(Color.Black, 1); SolidBrush aBrush = new SolidBrush(cs.TickColor); StringFormat sFormat = new StringFormat(); sFormat.Alignment = StringAlignment.Near; SizeF size = g.MeasureString("A", cs.TickFont); int x, y, width, height; Point3[] pts = new Point3[64]; PointF[] pta = new PointF[4]; float zmin, zmax; zmin = ds.ZDataMin(); zmax = ds.ZDataMax(); float dz = (zmax - zmin) / 63; x = 5 * form1.PlotPanel.Width / 6; y = form1.PlotPanel.Height / 10; width = form1.PlotPanel.Width / 25; height = 8 * form1.PlotPanel.Height / 10; // Add color bar: for (int i = 0; i < 64; i++) { pts[i] = new Point3(x, y, zmin + i * dz, 1); } for (int i = 0; i < 63; i++) { Color color = AddColor(cs, pts[i], zmin, zmax); aBrush = new SolidBrush(color); float y1 = y + height - (pts[i].Z - zmin) * height / (zmax - zmin); float y2 = y + height - (pts[i + 1].Z - zmin) * height / (zmax - zmin); pta[0] = new PointF(x, y2); pta[1] = new PointF(x + width, y2); pta[2] = new PointF(x + width, y1); pta[3] = new PointF(x, y1); g.FillPolygon(aBrush, pta); } g.DrawRectangle(aPen, x, y, width, height); // Add ticks and labels to the color bar: float ticklength = 0.1f * width; for (float z = zmin; z <= zmax; z = z + (zmax - zmin) / 6) { float yy = y + height - (z - zmin) * height / (zmax - zmin); g.DrawLine(aPen, x, yy, x + ticklength, yy); g.DrawLine(aPen, x + width, yy, x + width - ticklength, yy); g.DrawString((Math.Round(z, 2)).ToString(), cs.TickFont, Brushes.Black, new PointF(x + width + 5, yy - size.Height / 2), sFormat); } } }
private void Interp(Graphics g, ChartStyle cs, ChartStyle2D cs2d, Matrix3 m, Point3[] pta, float zmin, float zmax, int flag) { SolidBrush aBrush = new SolidBrush(Color.Black); PointF[] points = new PointF[4]; int npoints = NumberInterp; Point3[,] pts = new Point3[npoints + 1, npoints + 1]; Point3[,] pts1 = new Point3[npoints + 1, npoints + 1]; float x0 = pta[0].X; float y0 = pta[0].Y; float x1 = pta[2].X; float y1 = pta[2].Y; float dx = (x1 - x0) / npoints; float dy = (y1 - y0) / npoints; float C00 = pta[0].Z; float C10 = pta[3].Z; float C11 = pta[2].Z; float C01 = pta[1].Z; float x, y, C; Color color; if (flag == 1) // For Surface chart { for (int i = 0; i <= npoints; i++) { x = x0 + i * dx; for (int j = 0; j <= npoints; j++) { y = y0 + j * dy; C = (y1 - y) * ((x1 - x) * C00 + (x - x0) * C10) / (x1 - x0) / (y1 - y0) + (y - y0) * ((x1 - x) * C01 + (x - x0) * C11) / (x1 - x0) / (y1 - y0); pts[i, j] = new Point3(x, y, C, 1); pts[i, j].Transform(m, form1, cs); } } for (int i = 0; i < npoints; i++) { for (int j = 0; j < npoints; j++) { color = AddColor(cs, pts[i, j], zmin, zmax); aBrush = new SolidBrush(color); points[0] = new PointF(pts[i, j].X, pts[i, j].Y); points[1] = new PointF(pts[i + 1, j].X, pts[i + 1, j].Y); points[2] = new PointF(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y); points[3] = new PointF(pts[i, j + 1].X, pts[i, j + 1].Y); g.FillPolygon(aBrush, points); aBrush.Dispose(); } } } else if (flag == 2) // For XYColor chart { for (int i = 0; i <= npoints; i++) { x = x0 + i * dx; for (int j = 0; j <= npoints; j++) { y = y0 + j * dy; C = (y1 - y) * ((x1 - x) * C00 + (x - x0) * C10) / (x1 - x0) / (y1 - y0) + (y - y0) * ((x1 - x) * C01 + (x - x0) * C11) / (x1 - x0) / (y1 - y0); pts[i, j] = new Point3(x, y, C, 1); } } for (int i = 0; i < npoints; i++) { for (int j = 0; j < npoints; j++) { color = AddColor(cs, pts[i, j], zmin, zmax); aBrush = new SolidBrush(color); points[0] = cs2d.Point2D(new PointF(pts[i, j].X, pts[i, j].Y), cs); points[1] = cs2d.Point2D(new PointF(pts[i + 1, j].X, pts[i + 1, j].Y), cs); points[2] = cs2d.Point2D(new PointF(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y), cs); points[3] = cs2d.Point2D(new PointF(pts[i, j + 1].X, pts[i, j + 1].Y), cs); g.FillPolygon(aBrush, points); aBrush.Dispose(); } } } else if (flag == 3) // For XYColor3D chart { for (int i = 0; i <= npoints; i++) { x = x0 + i * dx; for (int j = 0; j <= npoints; j++) { y = y0 + j * dy; C = (y1 - y) * ((x1 - x) * C00 + (x - x0) * C10) / (x1 - x0) / (y1 - y0) + (y - y0) * ((x1 - x) * C01 + (x - x0) * C11) / (x1 - x0) / (y1 - y0); pts1[i, j] = new Point3(x, y, C, 1); pts[i, j] = new Point3(x, y, cs.ZMin, 1); pts[i, j].Transform(m, form1, cs); } } for (int i = 0; i < npoints; i++) { for (int j = 0; j < npoints; j++) { color = AddColor(cs, pts1[i, j], zmin, zmax); aBrush = new SolidBrush(color); points[0] = new PointF(pts[i, j].X, pts[i, j].Y); points[1] = new PointF(pts[i + 1, j].X, pts[i + 1, j].Y); points[2] = new PointF(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y); points[3] = new PointF(pts[i, j + 1].X, pts[i, j + 1].Y); g.FillPolygon(aBrush, points); aBrush.Dispose(); } } } }
private void AddSurface(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.White); Matrix3 m = Matrix3.AzimuthElevation(cs.Elevation, cs.Azimuth); PointF[] pta = new PointF[4]; Point3[,] pts = ds.PointArray; Point3[,] pts1 = new Point3[pts.GetLength(0), pts.GetLength(1)]; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); // Perform transformation on points: for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { // Make a deep copy the points array: pts1[i, j] = new Point3(pts[i, j].X, pts[i, j].Y, pts[i, j].Z, 1); // Perform transformation on points: pts[i, j].Transform(m, form1, cs); } } // Draw surface: if (!IsInterp) { for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { int ii = i; if (cs.Azimuth >= -180 && cs.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; } pta[0] = new PointF(pts[ii, j].X, pts[ii, j].Y); pta[1] = new PointF(pts[ii, j + 1].X, pts[ii, j + 1].Y); pta[2] = new PointF(pts[ii + 1, j + 1].X, pts[ii + 1, j + 1].Y); pta[3] = new PointF(pts[ii + 1, j].X, pts[ii + 1, j].Y); Color color = AddColor(cs, pts[ii, j], zmin, zmax); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta); } } } } // Draw refined surface: else if (IsInterp) { for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { int ii = i; if (cs.Azimuth >= -180 && cs.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; } Point3[] points = new Point3[4]; points[0] = pts1[ii, j]; points[1] = pts1[ii, j + 1]; points[2] = pts1[ii + 1, j + 1]; points[3] = pts1[ii + 1, j]; Interp(g, cs, cs2d, m, points, zmin, zmax, 1); pta[0] = new PointF(pts[ii, j].X, pts[ii, j].Y); pta[1] = new PointF(pts[ii, j + 1].X, pts[ii, j + 1].Y); pta[2] = new PointF(pts[ii + 1, j + 1].X, pts[ii + 1, j + 1].Y); pta[3] = new PointF(pts[ii + 1, j].X, pts[ii + 1, j].Y); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta);//网格可见 } } } } }