private void DrawGraph() { GraphPane pane = ZedGraph.GraphPane; pane.CurveList.Clear(); PointPairList f1_list = new PointPairList(); PointPairList f2_list = new PointPairList(); double xmin = -50; double xmax = 50; for (double x = xmin; x <= xmax; x += 0.01) { f1_list.Add(x, x * x); } for (double x = 0; x <= xmax; x += 0.5) { f2_list.Add(x, x * x * x); } LineItem f1_curve = pane.AddCurve("Sinc", f1_list, Color.Blue, SymbolType.None); LineItem f2_curve = pane.AddCurve("Sin", f2_list, Color.Red, SymbolType.Plus); ZedGraph.AxisChange(); ZedGraph.Invalidate(); }
private void zeggraph_init() { Panel = ZedGraph.GraphPane; counter = 0; Panel.Title.Text = "电机实时曲线"; Panel.Chart.Border.IsVisible = true; Panel.Legend.IsVisible = false; Panel.CurveList.Clear(); LineItem curve_moto_speed = Panel.AddCurve("电机", list_moto_speed, Color.Red, SymbolType.None); ZedGraph.Invalidate(); curve_moto_speed.Line.Width = 2F; curve_moto_speed.Symbol.Fill = new Fill(Color.White, Color.Blue, Color.White); curve_moto_speed.Symbol.Size = 5; Panel.XAxis.Title.Text = "个数"; Panel.XAxis.Scale.FontSpec.Size = 10; Panel.XAxis.Scale.Max = 1000; Panel.XAxis.Scale.Min = 0; Panel.XAxis.Scale.MajorStep = Panel.XAxis.Scale.Max / 10; Panel.XAxis.Scale.MinorStep = Panel.XAxis.Scale.MajorStep / 10; Panel.XAxis.MajorGrid.IsVisible = true; Panel.YAxis.Title.Text = "转速"; Panel.YAxis.Scale.FontSpec.Size = 10; Panel.YAxis.Scale.Max = 1500; Panel.YAxis.Scale.Min = -10; Panel.YAxis.Scale.MajorStep = 200; Panel.YAxis.Scale.MinorStep = 40; Panel.YAxis.MajorGrid.IsVisible = true; Panel.Chart.Fill = new Fill(Color.White, Color.SlateBlue, 23.0F); ZedGraph.AxisChange(); }
/// <summary> /// /// </summary> /// <param name="myGraphControl"></param> /// <param name="coor_x"></param> /// <param name="coor_y"></param> /// <param name="title"></param> /// <param name="Xtitle"></param> /// <param name="Ytitle"></param> public void MyDrawPic1(ZedGraph.ZedGraphControl myGraphControl, double[] coor_x, double[] coor_y, string title, string Xtitle, string Ytitle) { GraphPane myPane = myGraphControl.GraphPane; myPane.Legend.IsVisible = false; // myPane.CurveList.Clear(); //myPane.Title.Text = title; //myPane.XAxis.Title.Text = Xtitle; //myPane.YAxis.Title.Text = Ytitle; PointPairList list = new PointPairList(); int N = coor_x.Length; for (int i = 0; i < N; i++) { double x = coor_x[i]; double y = coor_y[i]; list.Add(x, y);//�������� } LineItem myCurve = myPane.AddCurve(title,list, Color.Black, SymbolType.None); myCurve.Symbol.Fill = new Fill(Color.White); myCurve.Line.Width = 2; //myCurve.IsX2Axis = false; //myCurve.IsY2Axis = false; myPane.XAxis.MajorGrid.IsVisible = false; myPane.YAxis.Scale.FontSpec.FontColor = Color.Black; myPane.YAxis.Title.FontSpec.FontColor = Color.Black; myPane.YAxis.MajorTic.IsOpposite = false; myPane.YAxis.MinorTic.IsOpposite = false; myPane.YAxis.MajorGrid.IsZeroLine = false; myPane.YAxis.Scale.Align = AlignP.Inside; myPane.YAxis.Scale.Min = -30; myPane.YAxis.Scale.Max = 30; myPane.Y2Axis.IsVisible = false; myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Black; myPane.Y2Axis.Title.FontSpec.FontColor = Color.Black; myPane.Y2Axis.MajorTic.IsOpposite = false; myPane.Y2Axis.MinorTic.IsOpposite = false; myPane.Y2Axis.MajorGrid.IsVisible = false; myPane.Y2Axis.Scale.Align = AlignP.Inside; myPane.Chart.Fill = new Fill(Color.White, Color.White, 45.0f); myGraphControl.IsShowPointValues = true; myGraphControl.PointValueEvent += new ZedGraph.ZedGraphControl.PointValueHandler(MyPointValueHandler); myGraphControl.ZoomEvent += new ZedGraph.ZedGraphControl.ZoomEventHandler(MyZoomEvent); myGraphControl.AxisChange(); myGraphControl.RestoreScale(myPane); myGraphControl.Invalidate(); }
private void chartBars(List <T> data, bool xlog, bool ylog) { if (data.Count == 0) { return; } pane.CurveList.Clear(); pane.XAxis.Title = data[0].Xname; pane.YAxis.Title = data[0].Yname; pane.XAxis.MinAuto = true; pane.YAxis.MinAuto = true; if (xlog) { pane.XAxis.Type = AxisType.Log; } else { pane.XAxis.Type = AxisType.Linear; } if (ylog) { pane.YAxis.Type = AxisType.Log; } else { pane.YAxis.Type = AxisType.Linear; } double[] XValues = new double[data.Count]; double[] YValues = new double[data.Count]; for (int i = 0; i < data.Count; i++) { XValues[i] = data[i].X; YValues[i] = data[i].Y; } pane.AddBar(BaseDataTable.Name, XValues, YValues, Color.Blue); pane.MinBarGap = 0.0f; pane.MinClusterGap = 2.5f; ZedGraph.AxisChange(); ZedGraph.Invalidate(); }
private void chartLinePoints(List <T> data, bool xlog, bool ylog) { if (data.Count == 0) { return; } pane.CurveList.Clear(); pane.XAxis.Title = data[0].Xname; pane.YAxis.Title = data[0].Yname; pane.XAxis.MinAuto = true; pane.YAxis.MinAuto = true; if (xlog) { pane.XAxis.Type = AxisType.Log; } else { pane.XAxis.Type = AxisType.Linear; } if (ylog) { pane.YAxis.Type = AxisType.Log; } else { pane.YAxis.Type = AxisType.Linear; } PointPairList list = new PointPairList(); foreach (var item in data) { list.Add(item.X, item.Y); } var curve = pane.AddCurve(BaseDataTable.Name, list, Color.Blue, SymbolType.Square); curve.Line.IsVisible = true; curve.Symbol.Fill.Type = FillType.Solid; curve.Symbol.Size = 3.0f; curve.Symbol.Fill.Color = Color.Blue; ZedGraph.AxisChange(); ZedGraph.Invalidate(); }
private void ItemOnClick(object sender, EventArgs eventArgs) { var pane = ZedGraph.GraphPane; var item = (ToolStripMenuItem)sender; if (pane.CurveList.Any(crv => crv.Label.Text == item.Text)) { pane.CurveList.Remove(pane.CurveList.Single(crv => crv.Label.Text == item.Text)); pane.YAxisList.Remove(pane.YAxisList.Single(ax => ax.Title.Text == item.Text)); AssignYAxes(pane); } else { var dataNameTag = (PlottableDataEnum)item.Tag; AddTrace(pane, dataNameTag); } ZedGraph.AxisChange(); ZedGraph.Invalidate(); }
private void OnLoad(object sender, EventArgs e) { OnLoadInternal(sender, e); // OPTIONAL: Show tooltips when the mouse hovers over a point ZedGraph.IsShowPointValues = true; ZedGraph.PointValueEvent += PointValueHandler; // OPTIONAL: Add a custom context menu item ZedGraph.ContextMenuBuilder += OnContextMenuBuilder; // OPTIONAL: Handle the Zoom Event ZedGraph.ZoomEvent += OnZoomEvent; // Tell ZedGraph to calculate the axis ranges // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets // up the proper scrolling parameters ZedGraph.AxisChange(); // Make sure the Graph gets redrawn ZedGraph.Invalidate(); }
/// <summary> /// /// </summary> /// <param name="myGraphControl"></param> /// <param name="X1"></param> /// <param name="Y1"></param> /// <param name="X2"></param> /// <param name="Y2"></param> /// <param name="title"></param> /// <param name="Xtitle"></param> /// <param name="Ytitle"></param> public void MyDrawPic2(ZedGraph.ZedGraphControl myGraphControl, double[] X1, double[] Y1, double[] X2, double[] Y2, string title, string Xtitle, string Ytitle) { GraphPane myPane = myGraphControl.GraphPane; myPane.Legend.IsVisible = false; myPane.CurveList.Clear(); myPane.Title.Text = title; myPane.XAxis.Title.Text = Xtitle; myPane.YAxis.Title.Text = Ytitle; PointPairList listr1 = new PointPairList(); PointPairList listr2 = new PointPairList(); PointPairList listr3 = new PointPairList(); for (int i = 0; i < X1.Length; i++) { listr1.Add(Convert.ToDouble(X1[i].ToString("f6")), Convert.ToDouble(Y1[i].ToString("f6"))); } for (int i = 0; i < X2.Length; i++) { listr2.Add(Convert.ToDouble(X2[i].ToString("f6")), Convert.ToDouble(Y2[i].ToString("f6"))); } //add rack curve LineItem myCurveR1 = myPane.AddCurve("title", listr1, Color.Blue, SymbolType.None); LineItem myCurveR2 = myPane.AddCurve("title", listr2, Color.Blue, SymbolType.None); LineItem myCurveR3 = myPane.AddCurve("title", listr3, Color.Blue, SymbolType.None); myCurveR1.Line.Width = 2; myCurveR2.Line.Width = 2; myCurveR3.Line.Width = 2; myCurveR1.Symbol.Fill = new Fill(Color.White); myCurveR2.Symbol.Fill = new Fill(Color.White); myCurveR3.Symbol.Fill = new Fill(Color.White); myCurveR1.IsY2Axis = true; myCurveR2.IsY2Axis = true; myCurveR3.IsY2Axis = true; myPane.XAxis.MajorGrid.IsVisible = true; myPane.YAxis.Scale.FontSpec.FontColor = Color.Black; myPane.YAxis.Title.FontSpec.FontColor = Color.Black; myPane.YAxis.MajorTic.IsOpposite = false; myPane.YAxis.MinorTic.IsOpposite = false; myPane.YAxis.MajorGrid.IsZeroLine = false; myPane.YAxis.Scale.Align = AlignP.Inside; myPane.YAxis.Scale.Min = -30; myPane.YAxis.Scale.Max = 30; myPane.Y2Axis.IsVisible = true; myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Black; myPane.Y2Axis.Title.FontSpec.FontColor = Color.Black; myPane.Y2Axis.MajorTic.IsOpposite = false; myPane.Y2Axis.MinorTic.IsOpposite = false; myPane.Y2Axis.MajorGrid.IsVisible = true; myPane.Y2Axis.Scale.Align = AlignP.Inside; myPane.Chart.Fill = new Fill(Color.White, Color.White, 45.0f); myGraphControl.IsShowPointValues = true; myGraphControl.PointValueEvent += new ZedGraph.ZedGraphControl.PointValueHandler(MyPointValueHandler); myGraphControl.ZoomEvent += new ZedGraph.ZedGraphControl.ZoomEventHandler(MyZoomEvent); myGraphControl.AxisChange(); myGraphControl.RestoreScale(myPane); myGraphControl.Invalidate(); Application.DoEvents(); Thread.Sleep(10);//��ͣ0.05�� }
public void DrawGraph(int z, int n, double a, double b) { ZedGraph.PointPairList F = new ZedGraph.PointPairList(); ZedGraph.PointPairList S = new ZedGraph.PointPairList(); ZedGraph.PointPairList F1 = new ZedGraph.PointPairList(); ZedGraph.PointPairList S1 = new ZedGraph.PointPairList(); ZedGraph.PointPairList F2 = new ZedGraph.PointPairList(); ZedGraph.PointPairList S2 = new ZedGraph.PointPairList(); ZedGraph.PointPairList e = new ZedGraph.PointPairList(); ZedGraph.PointPairList e1 = new ZedGraph.PointPairList(); ZedGraph.PointPairList e2 = new ZedGraph.PointPairList(); double h = (b - a) / n; for (int i = 0; i < n + 1; i++) { if (i % 4 == 0 && i != 0 && i != n) { continue; } double x0 = a + i * h; double FF = Function(x0, z); double SS = Spline(z, n, a, b, x0); double FF1 = Function1(x0, z); double SS1 = Spline1(z, n, a, b, x0); double FF2 = Function2(x0, z); double SS2 = Spline2(z, n, a, b, x0); double E = FF - SS; double E1 = FF1 - SS1; double E2 = FF2 - SS2; F.Add(x0, FF); S.Add(x0, SS); F1.Add(x0, FF1); S1.Add(x0, SS1); F2.Add(x0, FF2); S2.Add(x0, SS2); e.Add(x0, E); e1.Add(x0, E1); e2.Add(x0, E2); } ZedGraph.GraphPane.CurveList.Clear(); if (comboBox1.SelectedIndex == 0) { LineItem Curve = ZedGraph.GraphPane.AddCurve("F(x)", F, Color.Green, SymbolType.None); LineItem SCurve = ZedGraph.GraphPane.AddCurve("S(x)", S, Color.Blue, SymbolType.None); LineItem ECurve = ZedGraph.GraphPane.AddCurve("F(x)-S(x)", e, Color.Red, SymbolType.None); } if (comboBox1.SelectedIndex == 1) { LineItem Curve = ZedGraph.GraphPane.AddCurve("F'(x)", F1, Color.Green, SymbolType.None); LineItem SCurve = ZedGraph.GraphPane.AddCurve("S'(x)", S1, Color.Blue, SymbolType.None); LineItem ECurve = ZedGraph.GraphPane.AddCurve("F'(x)-S'(x)", e1, Color.Red, SymbolType.None); } if (comboBox1.SelectedIndex == 2) { LineItem Curve = ZedGraph.GraphPane.AddCurve("F''(x)", F2, Color.Green, SymbolType.None); LineItem SCurve = ZedGraph.GraphPane.AddCurve("S''(x)", S2, Color.Blue, SymbolType.None); LineItem ECurve = ZedGraph.GraphPane.AddCurve("F''(x)-S''(x)", e2, Color.Red, SymbolType.None); } ZedGraph.AxisChange(); ZedGraph.Invalidate(); }
public void CreateGraph(ZedGraph.ZedGraphControl zgc) { zgc.MasterPane.PaneList.Clear(); time1 = 0; time2 = 0; XScaleValue1 = Convert.ToInt16(XScale1.Value); XScaleValue2 = Convert.ToInt16(XScale2.Value); GraphPane myPane1 = new GraphPane(); GraphPane myPane2 = new GraphPane(); zgc.MasterPane.Add(myPane1); zgc.MasterPane.Add(myPane2); zgc.MasterPane.PaneList[0].Legend.IsVisible = false; zgc.MasterPane.PaneList[1].Legend.IsVisible = false; myPane1.Chart.Fill = new Fill(Color.Black); myPane2.Chart.Fill = new Fill(Color.Black); myPane1.Title.Text = "myPane1"; myPane1.Title.FontSpec.Size = 12F; myPane2.Title.Text = "myPane2"; myPane2.Title.FontSpec.Size = 12F; if (IsScrolling) { //zgc.IsAntiAlias = true; } list1.Add(0, 0); //Make a new curve BarItem RecentBar1 = myPane1.AddBar("RecentBar", RecentPoint1, Color.Red); RecentBar1.Bar.Fill = new Fill(Color.Red); RecentBar1.Bar.Border = new Border(Color.Red, 10.0F); BarItem RecentBar2 = myPane2.AddBar("RecentBar", RecentPoint2, Color.Red); RecentBar2.Bar.Fill = new Fill(Color.Red); RecentBar2.Bar.Border = new Border(Color.Red, 10.0F); BarItem curve = myPane1.AddBar("Average Counts", list1, Color.White); curve.Bar.Border = new Border(Color.White, 1.0F); //curve.Line.Fill = new Fill (Color.White); // curve.Line.IsVisible = false; BarItem curve2 = myPane2.AddBar("Counts (Avg ten)", list2, Color.White); curve2.Bar.Border = new Border(Color.White, 1.0F); //Timer fort the X axis, defined later timer1.Interval = 1; //10 - buffer size increases due to build up but levels out at about 112 bytes. timer1.Enabled = true; timer1.Start(); // Layout the GraphPanes using a default Pane Layout using (Graphics g = this.CreateGraphics()) { zgc.MasterPane.SetLayout(g, PaneLayout.SingleRow); } //Function to set axes of graphpanes. SetXAxis1(); SetXAxis2(); if (AutoScale.Checked == false) { SetYAxis1(); SetYAxis2(); } //Save begging time for reference tickStart = Environment.TickCount; Console.WriteLine("Create Graph"); zgc.Invalidate(); }
public void initialDateAxis(ZedGraph.ZedGraphControl zedChart) { if(this.m_dtLine1==null&&this.m_dtLine2==null) { return; } GraphPane myPane = zedChart.GraphPane; // Set the titles and axis labels myPane.Title = this.m_strTitle; //myPane. myPane.XAxis.Title =this.m_xAxisTitle; myPane.YAxis.Title = this.m_yAxisTitle; // Make up some data points based on the Sine function PointPairList list = new PointPairList(); for ( int i=0; i<this.m_dtLine1.Rows.Count; i++ ) { DateTime dt=Convert.ToDateTime(this.m_dtLine1.Rows[i]["x"].ToString()); double x = (double) new XDate( dt.Year,dt.Month, dt.Day); double y = Convert.ToDouble(this.m_dtLine1.Rows[i]["y"].ToString()); list.Add( x, y ); } PointPairList list1=new PointPairList(); for ( int i=0; i<this.m_dtLine2.Rows.Count; i++ ) { DateTime dt=Convert.ToDateTime(this.m_dtLine2.Rows[i]["x"].ToString()); double x = (double) new XDate(dt.Year,dt.Month,dt.Day,dt.Hour,dt.Minute,dt.Second); double y = Convert.ToDouble(this.m_dtLine2.Rows[i]["y"].ToString()); list1.Add( x, y ); } int iCount=0; string[] strXLabels; if(this.m_dtLine2.Rows.Count>this.m_dtLine1.Rows.Count) { iCount=this.m_dtLine2.Rows.Count; strXLabels=new string[iCount]; for(int i=0;i<iCount;i++) { DateTime dt=Convert.ToDateTime(this.m_dtLine2.Rows[i]["x"].ToString()); if(this.m_strState!="Day") strXLabels[i]=String.Format("{0}-{1}-{2}",dt.Year.ToString(),dt.Month.ToString(),dt.Day.ToString()); else strXLabels[i]=String.Format("{0}-{1}-{2} {3}:{4}:{5}",dt.Year.ToString(),dt.Month.ToString(),dt.Day.ToString(),dt.Hour.ToString(),dt.Minute.ToString(),dt.Second.ToString()); } } else { iCount=this.m_dtLine1.Rows.Count; strXLabels=new string[iCount]; for(int i=0;i<iCount;i++) { DateTime dt=Convert.ToDateTime(this.m_dtLine1.Rows[i]["x"].ToString()); if(this.m_strState!="Day") strXLabels[i]=String.Format("{0}-{1}-{2}",dt.Year.ToString(),dt.Month.ToString(),dt.Day.ToString()); else strXLabels[i]=String.Format("{0}-{1}-{2} {3}:{4}:{5}",dt.Year.ToString(),dt.Month.ToString(),dt.Day.ToString(),dt.Hour.ToString(),dt.Minute.ToString(),dt.Second.ToString()); } } myPane.CurveList.Clear(); // Generate a red curve with diamond // symbols, and "My Curve" in the legend LineItem myCurve = myPane.AddCurve( this.m_strLine1Name, list, Color.Black , SymbolType.Circle ); // myCurve = myPane.AddCurve( this.m_strLine2Name, // list1, Color.Green , SymbolType.Default ); myPane.XAxis.Type = AxisType.Text; myPane.XAxis.TextLabels=strXLabels; myPane.XAxis.ScaleFontSpec.Size=10; myPane.YAxis.ScaleFontSpec.Size=10; myCurve.Symbol.Fill = new Fill( Color.White); myCurve.Symbol.Size = 4; zedChart.AxisChange(); zedChart.Invalidate(); }
//Настройки графика void setup_graph(ZedGraph.ZedGraphControl graph) { var pane = graph.GraphPane; pane.YAxis.Title.Text = "y"; pane.X2Axis.Title.Text = "x"; //Настраиваем пересечение осей pane.XAxis.Cross = 0.0; pane.YAxis.Cross = 0.0; pane.XAxis.Scale.IsSkipFirstLabel = true; pane.XAxis.Scale.IsSkipLastLabel = true; pane.XAxis.Scale.IsSkipCrossLabel = true; pane.YAxis.Scale.IsSkipFirstLabel = true; pane.YAxis.Scale.IsSkipLastLabel = true; pane.YAxis.Scale.IsSkipCrossLabel = true; //Убираем засечки сверху и снизу pane.XAxis.MinorTic.IsOpposite = false; pane.XAxis.MajorTic.IsOpposite = false; pane.YAxis.MinorTic.IsOpposite = false; pane.YAxis.MajorTic.IsOpposite = false; graph.AxisChange(); graph.Invalidate(); }
public void initialDateAxis(ZedGraph.ZedGraphControl zedChart) { try { if(this.m_dtLine1==null&&this.m_dtLine2==null) { return; } GraphPane myPane = zedChart.GraphPane; // Set the titles and axis labels myPane.Title = this.m_strTitle; //myPane. myPane.XAxis.Title =this.m_xAxisTitle; myPane.YAxis.Title = this.m_yAxisTitle; double[] dDatas=new double[this.m_dtLine1.Rows.Count]; for(int i=0;i<this.m_dtLine1.Rows.Count;i++) { dDatas[i]=double.Parse(m_dtLine1.Rows[i]["y"].ToString().Trim()); } string[] strLabels=new string[this.m_dtLine1.Rows.Count]; for(int i=0;i<this.m_dtLine1.Rows.Count;i++) { if(this.isO(i)) { strLabels[i]=m_dtLine1.Rows[i]["x"].ToString().Trim(); } } myPane.CurveList.Clear(); LineItem myCurve = myPane.AddCurve(this.m_strLine1Name, null, dDatas, Color.Black, SymbolType.Circle); myPane.XAxis.Type = AxisType.Text; // Set the XAxis labels myPane.XAxis.TextLabels = strLabels; //myPane.XAxis.ScaleFontSpec.Angle = 40; myPane.XAxis.ScaleFontSpec.Size=10; myPane.YAxis.ScaleFontSpec.Size=10; myCurve.Symbol.Size = 4; zedChart.AxisChange(); zedChart.Invalidate(); } catch(Exception ex) { cSaveErr.CSaveErr.msgboxErr(ex.ToString()); } }