public override void DrawLine(object tChart, plotData temp, string seriName, LineType lineType) { ZedGraphControl chart = (ZedGraphControl)tChart; GraphPane myPane = chart.GraphPane; if (chart.InvokeRequired) { SetDrawLineCallBack d = DrawLine; chart.Invoke(d, new object[] { chart, temp, seriName, lineType }); } else { PointPairList list = new PointPairList(); //int length = temp.xData.Length; //for (int i = 0; i < length; i++) //{ // list.Add(temp.xData[i],temp.yData[i]); //} //double[]a=new double[100]; // Generate a blue curve with circle symbols, and "My Curve 2" in the legend LineItem myCurve1 = new LineItem(seriName, temp.xData.Select(x => (double)x).ToArray(), temp.yData.Select(x => (double)x).ToArray(), lineType == LineType.Spec ? Color.Red : GetRandomColor(), SymbolType.None, 1.5f); myCurve1.Line.IsSmooth = true; myCurve1.Line.IsAntiAlias = true; myCurve1.Line.SmoothTension = 0.1F; myCurve1.Line.GradientFill.Type = FillType.Brush; myPane.CurveList.Add(myCurve1); // myPane.AddCurve(seriName, temp.xData.Select(x => (double)x).ToArray(), temp.yData.Select(x => (double)x).ToArray(), lineType == LineType.Spec ? Color.Red : Util.getRandomColor(), SymbolType.None); myPane.Legend.Position = LegendPos.InsideBotRight; //chart.Font = new System.Drawing.Font("Consolas", 20.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); myPane.Legend.FontSpec.Family = "Consolas"; // myPane.Legend.FontSpec.Size = 25; chart.AxisChange(); //chart.IsAntiAlias = true; chart.Refresh(); } }
private plotData TrimNaN(plotData plotData) { Draw.plotData ret = new plotData(); int length = plotData.yData.Length; List <float> x = new List <float>(); List <float> y = new List <float>(); for (int i = 0; i < length; i++) { if (!float.IsNaN(plotData.yData[i])) { x.Add(plotData.xData[i]); y.Add(plotData.yData[i]); } } ret.xData = x.ToArray(); ret.yData = y.ToArray(); return(ret); }
public override void DrawLine(object tChart, plotData temp, string seriName, LineType lineType) { ChartXy chart = (ChartXy)tChart; if (chart.ChartControl.InvokeRequired) { SetDrawLineCallBack d = DrawLine; chart.ChartControl.Invoke(d, new object[] { chart, temp, seriName, lineType }); } else { ChartSeries series = new ChartSeries(seriName, SeriesType.Line); //绑定数据 for (int i = 0; i < temp.xData.Length; i++) { SeriesPoint sp = new SeriesPoint(temp.xData[i], temp.yData[i]); series.SeriesPoints.Add(sp); } // series.ChartSeriesVisualStyle.LineStyle.LineColor = Color.Maroon; series.ChartSeriesVisualStyle.LineStyle.LineWidth = 2; series.ChartSeriesVisualStyle.LineStyle.LinePattern = LinePattern.Solid; chart.ChartSeries.Add(series); //switch (lineType) //{ // case LineType.Fre: // for (int i = 1; i < 10; i++) // { // CustomLabel label = new CustomLabel(); // label.Text = (i * 5).ToString() + "Ghz"; // label.ToPosition = i * 10000000000; // chart.ChartAreas[0].AxisX.CustomLabels.Add(label); // label.GridTicks = GridTickTypes.Gridline; // } // break; // case LineType.Time: // for (int i = 1; i < 10; i++) // { // CustomLabel label = new CustomLabel(); // label.Text = (i * 1).ToString() + "ns"; // label.ToPosition = (float) i * 2; // chart.ChartAreas[0].AxisX.CustomLabels.Add(label); // label.GridTicks = GridTickTypes.Gridline; // } // break; //} } }
public override void DrawLine(object oChart, plotData temp, string seriName, LineType lineType) { Chart chart = (Chart)oChart; if (chart.InvokeRequired) { SetDrawLineCallBack d = DrawLine; chart.Invoke(d, new object[] { chart, temp, seriName, lineType }); } else { //绑定数据 int index = chart.Series.Count; chart.Series.Add(seriName); Series currentSeries = chart.Series[index]; currentSeries.SetCustomProperty("CHECK", "☑"); //chart.Titles[index].Alignment = System.Drawing.ContentAlignment.TopRight; currentSeries.XValueType = ChartValueType.Single; //设置X轴上的值类型 //currentSeries.Label = "#VAL"; //设置显示X Y的值 //currentSeries.LabelForeColor = Color.Black; // currentSeries.ToolTip = "#VALX:#VAL"; //鼠标移动到对应点显示数值 currentSeries.ToolTip = string.Format("X - {0}/{2} , Y - {1}", "#VALX", "#VALY{F2}", 1000); //鼠标移动到对应点显示数值 currentSeries.ChartType = SeriesChartType.FastLine; //图类型(折线) //currentSeries.ChartType = SeriesChartType.Line; //图类型(折线) currentSeries.IsValueShownAsLabel = false; currentSeries.LegendText = seriName; currentSeries.IsVisibleInLegend = true; currentSeries.BorderWidth = 1; //chart.Legends[seriName].Enabled = true; //chart.Legends[seriName].MaximumAutoSize = 15; //chart.Series[0].IsValueShownAsLabel = true; // currentSeries.LabelForeColor = Color.Black; // currentSeries.CustomProperties = "DrawingStyle = Cylinder"; if (lineType == LineType.Spec) { plotData trimPlotData = TrimNaN(temp); currentSeries.Points.DataBindXY(trimPlotData.xData, trimPlotData.yData); } else { currentSeries.Points.DataBindXY(temp.xData, temp.yData); } //currentSeries.Points.AddXY(temp.xData, temp.yData); //CalloutAnnotation annotation = new CalloutAnnotation(); //annotation.Text = seriName + ":" + temp.yData[0]; //chart.Annotations.Add(annotation); //int anCount = chart.Annotations.Count; //var aa = currentSeries.Points; //chart.Annotations[anCount-1].AnchorDataPoint = currentSeries.Points[0]; switch (lineType) { case LineType.Fre: for (int i = 1; i < 10; i++) { CustomLabel label = new CustomLabel(); label.Text = (i * 5).ToString() + "Ghz"; label.ToPosition = i * 10000000000; chart.ChartAreas[0].AxisX.CustomLabels.Add(label); label.GridTicks = GridTickTypes.TickMark; } break; case LineType.Time: for (int i = 1; i < 10; i++) { CustomLabel label = new CustomLabel(); label.Text = (i * 1).ToString() + "ns"; label.ToPosition = (float)i * 2; chart.ChartAreas[0].AxisX.CustomLabels.Add(label); label.GridTicks = GridTickTypes.TickMark; } break; case LineType.Spec: currentSeries.Color = Color.Red; currentSeries.BorderWidth = 2; break; } Extende.SelectTab(chart); //chart.Visible = true; } }
public abstract void DrawLine(object tChart, plotData temp, string seriName, LineType lineType);