/// <summary> /// Copy constructor /// </summary> /// public ChartStyle(ChartStyle rhs) { _mxMax = rhs._mxMax; _mxMin = rhs._mxMin; _myMax = rhs._myMax; _myMin = rhs._myMin; _mzMax = rhs._mzMax; _mzMin = rhs._mzMin; _mxTick = rhs._mxTick; _myTick = rhs._myTick; _mzTick = rhs._mzTick; _mtickFont = rhs._mtickFont; _mtickColor = rhs._mtickColor; _mtitle = rhs._mtitle; _mtitleFont = rhs._mtitleFont; _mtitleColor = rhs._mtitleColor; _mxLabel = rhs._mxLabel; _myLabel = rhs._myLabel; _mzLabel = rhs._mzLabel; _mlabelFont = rhs._mlabelFont; _mlabelColor = rhs._mlabelColor; _melevation = rhs._melevation; _mazimuth = rhs._mazimuth; _misXGrid = rhs._misXGrid; _misYGrid = rhs._misYGrid; _misZGrid = rhs._misZGrid; _mgridStyle = rhs._mgridStyle; _maxisStyle = rhs._maxisStyle; _misColorBar = rhs._misColorBar; }
private void AddMesh(Graphics g, DataSeries ds, ChartStyle cs) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.Red); Matrix3 m = Matrix3.AzimuthElevation(cs.Elevation, cs.Azimuth); PointF[] pta = new PointF[4]; Point3[,] pts = ds.PointArray; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); // Perform transformations on points: for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { pts[i, j].Transform(m, form1, cs); } } // Draw color mesh: 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); if (!IsHiddenLine) { g.FillPolygon(aBrush, pta); } if (IsColorMap) { Color color = AddColor(cs, pts[ii, j], zmin, zmax); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } aPen.Dispose(); aBrush.Dispose(); }
/// <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); } } }
public void AddChartStyle2D(Graphics g, ChartStyle cs3d) { Pen aPen = new Pen(Color.Black, 1f); SizeF tickFontSize = g.MeasureString("A", cs3d.TickFont); // Create vertical gridlines: float fX, fY; if (cs3d.IsYGrid == true) { aPen = new Pen(cs3d.GridStyle.LineColor, 1f); aPen.DashStyle = cs3d.GridStyle.Pattern; for (fX = cs3d.XMin + cs3d.XTick; fX < cs3d.XMax; fX += cs3d.XTick) { g.DrawLine(aPen, Point2D(new PointF(fX, cs3d.YMin), cs3d), Point2D(new PointF(fX, cs3d.YMax), cs3d)); } } // Create horizontal gridlines: if (cs3d.IsXGrid == true) { aPen = new Pen(cs3d.GridStyle.LineColor, 1f); aPen.DashStyle = cs3d.GridStyle.Pattern; for (fY = cs3d.YMin + cs3d.YTick; fY < cs3d.YMax; fY += cs3d.YTick) { g.DrawLine(aPen, Point2D(new PointF(cs3d.XMin, fY), cs3d), Point2D(new PointF(cs3d.XMax, fY), cs3d)); } } // Create the x-axis tick marks: for (fX = cs3d.XMin; fX <= cs3d.XMax; fX += cs3d.XTick) { PointF yAxisPoint = Point2D(new PointF(fX, cs3d.YMin), cs3d); g.DrawLine(Pens.Black, yAxisPoint, new PointF(yAxisPoint.X, yAxisPoint.Y - 5f)); } // Create the y-axis tick marks: for (fY = cs3d.YMin; fY <= cs3d.YMax; fY += cs3d.YTick) { PointF xAxisPoint = Point2D(new PointF(cs3d.XMin, fY), cs3d); g.DrawLine(Pens.Black, xAxisPoint, new PointF(xAxisPoint.X + 5f, xAxisPoint.Y)); } aPen.Dispose(); }
public PointF Point2D(PointF pt, ChartStyle cs3d) { PointF aPoint = new PointF(); if (pt.X < cs3d.XMin || pt.X > cs3d.XMax || pt.Y < cs3d.YMin || pt.Y > cs3d.YMax) { pt.X = Single.NaN; pt.Y = Single.NaN; } aPoint.X = (pt.X - cs3d.XMin) * form1.PlotPanel.Width / (cs3d.XMax - cs3d.XMin); aPoint.Y = form1.PlotPanel.Height - (pt.Y - cs3d.YMin) * form1.PlotPanel.Height / (cs3d.YMax - cs3d.YMin); return(aPoint); }
/// <summary> /// 创建用于绘制三维折线图的数据 /// </summary> /// <param name="ds"></param> /// <param name="cs"></param> public void Line3D(DataSeries ds, ChartStyle cs) { cs.XMin = -1f; cs.XMax = 1f; cs.YMin = -1f; cs.YMax = 1f; cs.ZMin = 0; cs.ZMax = 30; cs.XTick = 0.5f; cs.YTick = 0.5f; cs.ZTick = 5; ds.XDataMin = cs.XMin; ds.YDataMin = cs.YMin; ds.XSpacing = 0.3f; ds.YSpacing = 0.3f; ds.XNumber = Convert.ToInt16((cs.XMax - cs.XMin) / ds.XSpacing) + 1; ds.YNumber = Convert.ToInt16((cs.YMax - cs.YMin) / ds.YSpacing) + 1; ds.PointList.Clear(); for (int i = 0; i < 300; i++) { float t = 0.1f * i; float x = (float)Math.Exp(-t / 30) * (float)Math.Cos(t); float y = (float)Math.Exp(-t / 30) * (float)Math.Sin(t); float z = t; ds.AddPoint(new Point3(x, y, z, 1)); } //float x, y, z; //for (int i = 0; i < 1; i++) //{ // x = 0.1f * i; // for (int j = 0; j < 10; j++) // { // y = 0.1f * j; // z = 20 * y; // ds.AddPoint(new Point3(x, y, z, 1)); // } //} }
/// <summary> /// 为特定的三维图形类型创建颜色映射 /// </summary> /// <param name="cs"></param> /// <param name="pt"></param> /// <param name="zmin"></param> /// <param name="zmax"></param> /// <returns></returns> private Color AddColor(ChartStyle cs, Point3 pt, float zmin, float zmax) { int colorLength = CMap.GetLength(0); int cindex = (int)Math.Round((colorLength * (pt.Z - zmin) + (zmax - pt.Z)) / (zmax - zmin)); if (cindex < 1) { cindex = 1; } if (cindex > colorLength) { cindex = colorLength; } Color color = Color.FromArgb(CMap[cindex - 1, 0], CMap[cindex - 1, 1], CMap[cindex - 1, 2], CMap[cindex - 1, 3]); return(color); }
/// <summary> /// 随机数据 /// </summary> /// <param name="ds"></param> /// <param name="cs"></param> public void RandData(DataSeries ds, ChartStyle cs) { randdata++; cs.XMin = -8; cs.XMax = 8; cs.YMin = -randdata; cs.YMax = -randdata + 16; cs.ZMin = -1f; cs.ZMax = 16; cs.XTick = 4; cs.YTick = 4; cs.ZTick = 4f; ds.XDataMin = cs.XMin; ds.YDataMin = cs.YMin; ds.XSpacing = 1f; ds.YSpacing = 1f; ds.XNumber = Convert.ToInt16((cs.XMax - cs.XMin) / ds.XSpacing) + 1; ds.YNumber = Convert.ToInt16((cs.YMax - cs.YMin) / ds.YSpacing) + 1; Random rd = new Random(); Point3[,] pts = new Point3[ds.XNumber, ds.YNumber]; for (int i = 0; i < ds.XNumber; i++) { for (int j = 0; j < ds.YNumber; j++) { float x = ds.XDataMin + i * ds.XSpacing; float y = ds.YDataMin + j * ds.YSpacing;//时间轴 //float z = 2 * x + randdata / 10+(float)j/5; float z = rd.Next(16); pts[i, j] = new Point3(x, y, z, 1); } } ds.PointArray = pts; if (randdata >= 10) { randdata = 0; } }
/// <summary> /// 测试切片图的标量量数据 /// </summary> /// <param name="ds"></param> /// <param name="cs"></param> public void Exp4D(DataSeries ds, ChartStyle cs) { cs.XMin = -2; cs.XMax = 2; cs.YMin = -2; cs.YMax = 2; cs.ZMin = -2; cs.ZMax = 2; cs.XTick = 1; cs.YTick = 1; cs.ZTick = 1; ds.XDataMin = cs.XMin; ds.YDataMin = cs.YMin; ds.ZZDataMin = cs.ZMin; ds.XSpacing = 0.1f; ds.YSpacing = 0.1f; ds.ZSpacing = 0.1f; ds.XNumber = Convert.ToInt16((cs.XMax - cs.XMin) / ds.XSpacing) + 1; ds.YNumber = Convert.ToInt16((cs.YMax - cs.YMin) / ds.YSpacing) + 1; ds.ZNumber = Convert.ToInt16((cs.ZMax - cs.ZMin) / ds.ZSpacing) + 1; Point4[, ,] pts = new Point4[ds.XNumber, ds.YNumber, ds.ZNumber]; for (int i = 0; i < ds.XNumber; i++) { for (int j = 0; j < ds.YNumber; j++) { for (int k = 0; k < ds.ZNumber; k++) { float x = ds.XDataMin + i * ds.XSpacing; float y = ds.YDataMin + j * ds.YSpacing; float z = cs.ZMin + k * ds.ZSpacing; float v = z * (float)Math.Exp(-x * x - y * y - z * z); pts[i, j, k] = new Point4(new Point3(x, y, z, 1), v); } } } ds.Point4Array = pts; }
/// <summary> /// 随机数据 /// </summary> /// <param name="ds"></param> /// <param name="cs"></param> public void Show3DData(DataSeries ds, ChartStyle cs) { cs.XMin = 0; cs.XMax = 700; cs.YMin = 0; cs.YMax = 10; cs.ZMin = 0f; cs.ZMax = 1000000; cs.XTick = 100;//大tick cs.YTick = 2; cs.ZTick = 250000f; ds.XDataMin = cs.XMin; ds.YDataMin = cs.YMin; ds.XSpacing = 1f;//小tick ds.YSpacing = 1f; //ds.ZSpacing = 1f; ds.XNumber = 500; //ds.XNumber = Convert.ToInt16((cs.XMax - cs.XMin) / ds.XSpacing) ; ds.YNumber = Convert.ToInt16((cs.YMax - cs.YMin) / ds.YSpacing);//==================多减了个1 Random rd = new Random(); Point3[,] pts = new Point3[ds.XNumber, ds.YNumber]; for (int i = 0; i < ds.XNumber; i++) { for (int j = 0; j < ds.YNumber; j++) { float x = (float)StaticData.ListPoint[j][i].X; float y = j; float z = (float)StaticData.ListPoint[j][i].Y;; if (z > 1000000) { z = 1000000; } pts[i, j] = new Point3(x, y, z, 1); } } ds.PointArray = pts; }
private void AddLine(Graphics g, DataSeries ds, ChartStyle cs) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; Matrix3 m = Matrix3.AzimuthElevation(cs.Elevation, cs.Azimuth); Point3[] pts = new Point3[ds.PointList.Count]; // Find zmin and zmax values, then perform transformation on points: float zmin = 0; float zmax = 0; for (int i = 0; i < pts.Length; i++) { pts[i] = (Point3)ds.PointList[i]; zmin = Math.Min(zmin, pts[i].Z); zmax = Math.Max(zmax, pts[i].Z); pts[i].Transform(m, form1, cs); } // Draw line: if (ds.LineStyle.IsVisible == true) { for (int i = 1; i < pts.Length; i++) { Color color = AddColor(cs, pts[i], zmin, zmax); if (IsColorMap) { aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawLine(aPen, pts[i - 1].X, pts[i - 1].Y, pts[i].X, pts[i].Y); } } aPen.Dispose(); }
/// <summary> /// 测试网格图 /// </summary> /// <param name="ds"></param> /// <param name="cs"></param> public void Peak3D(DataSeries ds, ChartStyle cs) { cs.XMin = -3; cs.XMax = 3; cs.YMin = -3; cs.YMax = 3; cs.ZMin = -8; cs.ZMax = 8; cs.XTick = 1; cs.YTick = 1; cs.ZTick = 4; ds.XDataMin = cs.XMin; ds.YDataMin = cs.YMin; ds.XSpacing = 0.3f; ds.YSpacing = 0.3f; ds.XNumber = Convert.ToInt16((cs.XMax - cs.XMin) / ds.XSpacing) + 1; ds.YNumber = Convert.ToInt16((cs.YMax - cs.YMin) / ds.YSpacing) + 1; Point3[,] pts = new Point3[ds.XNumber, ds.YNumber]; for (int i = 0; i < ds.XNumber; i++) { for (int j = 0; j < ds.YNumber; j++) { float x = ds.XDataMin + i * ds.XSpacing; float y = ds.YDataMin + j * ds.YSpacing; double zz = 3 * Math.Pow((1 - x), 2) * Math.Exp(-x * x - (y + 1) * (y + 1)) - 10 * (0.2 * x - Math.Pow(x, 3) - Math.Pow(y, 5)) * Math.Exp(-x * x - y * y) - 1 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y); float z = (float)zz; pts[i, j] = new Point3(x, y, z, 1); } } ds.PointArray = pts; }
private void AddMeshZ(Graphics g, DataSeries ds, ChartStyle cs) { 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)]; Color color; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); 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 transformations on points: pts[i, j].Transform(m, form1, cs); } } //Draw mesh using Z-order method: 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); g.FillPolygon(aBrush, pta); if (IsColorMap) { color = AddColor(cs, pts[ii, j], zmin, zmax); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } //Draw cyrtain lines Point3[] pt3 = new Point3[4]; for (int i = 0; i < pts1.GetLength(0); i++) { int jj = pts1.GetLength(0) - 1; if (cs.Elevation >= 0) { if (cs.Azimuth >= -90 && cs.Azimuth <= 90) { jj = 0; } } else if (cs.Elevation < 0) { jj = 0; if (cs.Azimuth >= -90 && cs.Azimuth <= 90) { jj = pts1.GetLength(0) - 1; } } if (i < pts1.GetLength(0) - 1) { pt3[0] = new Point3(pts1[i, jj].X, pts1[i, jj].Y, pts1[i, jj].Z, 1); pt3[1] = new Point3(pts1[i + 1, jj].X, pts1[i + 1, jj].Y, pts1[i + 1, jj].Z, 1); pt3[2] = new Point3(pts1[i + 1, jj].X, pts1[i + 1, jj].Y, cs.ZMin, 1); pt3[3] = new Point3(pts1[i, jj].X, pts1[i, jj].Y, cs.ZMin, 1); for (int k = 0; k < 4; k++) { pt3[k].Transform(m, form1, cs); } pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); g.FillPolygon(aBrush, pta); if (IsColorMap) { color = AddColor(cs, pt3[0], zmin, zmax); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } for (int j = 0; j < pts1.GetLength(1); j++) { int ii = 0; if (cs.Elevation >= 0) { if (cs.Azimuth >= 0 && cs.Azimuth <= 180) { ii = pts1.GetLength(1) - 1; } } else if (cs.Elevation < 0) { if (cs.Azimuth >= -180 && cs.Azimuth <= 0) { ii = pts1.GetLength(1) - 1; } } if (j < pts1.GetLength(1) - 1) { pt3[0] = new Point3(pts1[ii, j].X, pts1[ii, j].Y, pts1[ii, j].Z, 1); pt3[1] = new Point3(pts1[ii, j + 1].X, pts1[ii, j + 1].Y, pts1[ii, j + 1].Z, 1); pt3[2] = new Point3(pts1[ii, j + 1].X, pts1[ii, j + 1].Y, cs.ZMin, 1); pt3[3] = new Point3(pts1[ii, j].X, pts1[ii, j].Y, cs.ZMin, 1); for (int k = 0; k < 4; k++) { pt3[k].Transform(m, form1, cs); } pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); g.FillPolygon(aBrush, pta); if (IsColorMap) { color = AddColor(cs, pt3[0], zmin, zmax); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } aPen.Dispose(); aBrush.Dispose(); }
private void AddLabels(Graphics g, ChartStyle cs3d) { float xOffset = ChartArea.Width / 30.0f; float yOffset = ChartArea.Height / 30.0f; SizeF labelFontSize = g.MeasureString("A", cs3d.LabelFont); SizeF titleFontSize = g.MeasureString("A", cs3d.TitleFont); SizeF tickFontSize = g.MeasureString("A", cs3d.TickFont); SolidBrush aBrush = new SolidBrush(cs3d.TickColor); StringFormat sFormat = new StringFormat(); // Create the x-axis tick marks: aBrush = new SolidBrush(cs3d.TickColor); for (float fX = cs3d.XMin; fX <= cs3d.XMax; fX += cs3d.XTick) { PointF yAxisPoint = Point2D(new PointF(fX, cs3d.YMin), cs3d); sFormat.Alignment = StringAlignment.Far; SizeF sizeXTick = g.MeasureString(fX.ToString(), cs3d.TickFont); g.DrawString(fX.ToString(), cs3d.TickFont, aBrush, new PointF(yAxisPoint.X + sizeXTick.Width / 2 + form1.PlotPanel.Left, yAxisPoint.Y + 4f + form1.PlotPanel.Top), sFormat); } // Create the y-axis tick marks: for (float fY = cs3d.YMin; fY <= cs3d.YMax; fY += cs3d.YTick) { PointF xAxisPoint = Point2D(new PointF(cs3d.XMin, fY), cs3d); sFormat.Alignment = StringAlignment.Far; g.DrawString(fY.ToString(), cs3d.TickFont, aBrush, new PointF(xAxisPoint.X - 3f + form1.PlotPanel.Left, xAxisPoint.Y - tickFontSize.Height / 2 + form1.PlotPanel.Top), sFormat); } // Add horizontal axis label: aBrush = new SolidBrush(cs3d.LabelColor); SizeF stringSize = g.MeasureString(cs3d.XLabel, cs3d.LabelFont); g.DrawString(cs3d.XLabel, cs3d.LabelFont, aBrush, new Point(form1.PlotPanel.Left + form1.PlotPanel.Width / 2 - (int)stringSize.Width / 2, ChartArea.Bottom - (int)yOffset - (int)labelFontSize.Height)); // Add y-axis label: sFormat.Alignment = StringAlignment.Center; stringSize = g.MeasureString(cs3d.YLabel, cs3d.LabelFont); // Save the state of the current Graphics object GraphicsState gState = g.Save(); g.TranslateTransform(xOffset, yOffset + titleFontSize.Height + yOffset / 3 + form1.PlotPanel.Height / 2); g.RotateTransform(-90); g.DrawString(cs3d.YLabel, cs3d.LabelFont, aBrush, 0, 0, sFormat); // Restore it: g.Restore(gState); // Add title: aBrush = new SolidBrush(cs3d.TitleColor); stringSize = g.MeasureString(cs3d.Title, cs3d.TitleFont); if (cs3d.Title.ToUpper() != "NO TITLE") { g.DrawString(cs3d.Title, cs3d.TitleFont, aBrush, new Point(form1.PlotPanel.Left + form1.PlotPanel.Width / 2 - (int)stringSize.Width / 2, ChartArea.Top + (int)yOffset)); } aBrush.Dispose(); }
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(); } } } }
/// <summary> /// 读取外部文件数据 /// </summary> /// <param name="ds"></param> /// <param name="cs"></param> public void ReadDataFromFile(DataSeries ds, ChartStyle cs) { string inputdata = ""; int count = 0; int n = 0; string[] readArray = new string[2]; float[] xvalue = new float[2], yvalue = new float[2], zvalue = new float[2]; cs.XMin = -3; cs.XMax = 3; cs.YMin = -3; cs.YMax = 3; cs.ZMin = -8; cs.ZMax = 8; cs.XTick = 1; cs.YTick = 1; cs.ZTick = 4; //Read data from file string filename = System.AppDomain.CurrentDomain.BaseDirectory + "testingdata.txt"; StreamReader sr = new StreamReader(filename); char[] cSplitter = { ' ', ',', ':', '\t' }; inputdata = sr.ReadLine(); readArray = inputdata.Split(cSplitter); xvalue = new float[readArray.Length - 1]; yvalue = new float[readArray.Length - 1]; zvalue = new float[xvalue.Length * yvalue.Length]; for (int i = 0; i < xvalue.Length; i++) { xvalue[i] = float.Parse(readArray[i + 1]); } while (inputdata != null) { inputdata = sr.ReadLine(); if (inputdata == null) { break; } readArray = inputdata.Split(cSplitter); yvalue[n] = float.Parse(readArray[0]); for (int i = 0; i < yvalue.Length; i++) { zvalue[count] = float.Parse(readArray[i + 1]); count++; } n++; } Point3[,] pts = new Point3[xvalue.Length, yvalue.Length]; float x, y, z; for (int i = 0; i < xvalue.Length; i++) { x = xvalue[i]; for (int j = 0; j < yvalue.Length; j++) { y = yvalue[j]; z = zvalue[j + i * yvalue.Length]; //pts[i - 1, j - 1] = new Point3(x, y, z, 1); pts[i, j] = new Point3(x, y, z, 1); } } ds.PointArray = pts;//取出文件里的数据——显示 ds.XDataMin = pts[0, 0].X; ds.YDataMin = pts[0, 0].Y; ds.XSpacing = pts[1, 0].X - pts[0, 0].X; ds.YSpacing = pts[0, 1].Y - pts[0, 0].Y; ds.XNumber = pts.GetLength(0); ds.YNumber = pts.GetLength(1); }
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);//网格可见 } } } } }
private void AddWaterfall(Graphics g, DataSeries ds, ChartStyle cs) { 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); Point3[,] pts = ds.PointArray; Point3[] pt3 = new Point3[pts.GetLength(0) + 2]; PointF[] pta = new PointF[pts.GetLength(0) + 2]; Color color; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); for (int j = 0; j < pts.GetLength(1); j++) { int jj = j; if (cs.Elevation >= 0) { if (cs.Azimuth >= -90 && cs.Azimuth < 90) { jj = pts.GetLength(1) - 1 - j; } } else if (cs.Elevation < 0) { jj = pts.GetLength(1) - 1 - j; if (cs.Azimuth >= -90 && cs.Azimuth < 90) { jj = j; } } for (int i = 0; i < pts.GetLength(0); i++) { pt3[i + 1] = pts[i, jj]; if (i == 0) { pt3[0] = new Point3(pt3[i + 1].X, pt3[i + 1].Y, cs.ZMin, 1); } if (i == pts.GetLength(0) - 1) { pt3[pts.GetLength(0) + 1] = new Point3(pt3[i + 1].X, pt3[i + 1].Y, cs.ZMin, 1); } } for (int i = 0; i < pt3.Length; i++) { pt3[i].Transform(m, form1, cs); pta[i] = new PointF(pt3[i].X, pt3[i].Y); } g.FillPolygon(aBrush, pta); for (int i = 1; i < pt3.Length; i++) { if (IsColorMap) { color = AddColor(cs, pt3[i], zmin, zmax); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawLine(aPen, pta[i - 1], pta[i]); } } aPen.Dispose(); aBrush.Dispose(); }