private void Form1_Load(object sender, EventArgs e) { // Get a reference to the GraphPane instance in the ZedGraphControl GraphPane myPane = zg1.GraphPane; // Set the titles and axis labels myPane.Title.Text = "Demonstration of Dual Y Graph"; myPane.XAxis.Title.Text = "Time, Days"; myPane.YAxis.Title.Text = "Parameter A"; myPane.Y2Axis.Title.Text = "Parameter B"; // Make up some data points based on the Sine function PointPairList list = new PointPairList(); PointPairList list1 = new PointPairList(); PointPairList list2 = new PointPairList(); PointPairList list3 = new PointPairList(); for (double i = -36; i < 36; i += 1) { double x = (double)i * 10; double y = Math.Sin((double)i * Math.PI / 15.0) * 16.0; //double y = ((2 / (1 + Math.Exp( x))) - 1); double y1 = ((2 / (1 + Math.Exp(y * (double)numericUpDown1.Value + (double)numericUpDown3.Value))) - 1); double y2 = ((2 / (1 + Math.Exp(y * (double)numericUpDown2.Value + (double)numericUpDown4.Value))) - 1); list.Add(x, y); list1.Add(x, y1); list2.Add(x, y2); double y3 = y1 * (double)numericUpDown5.Value + y2 * (double)numericUpDown6.Value; y3 += (double)numericUpDown7.Value; y3 = ((2 / (1 + Math.Exp(y3))) - 1); list3.Add(x, y3); } myPane.ClearCurve(); // Generate a red curve with diamond symbols, and "Alpha" in the legend LineItem myCurve = myPane.AddCurve("sample", list, Color.Black, SymbolType.Diamond); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); if (checkBox1.Checked == true) { // Generate a blue curve with circle symbols, and "Beta" in the legend myCurve = myPane.AddCurve("Red", list1, Color.Red, SymbolType.Circle); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // Associate this curve with the Y2 axis myCurve.IsY2Axis = true; } if (checkBox2.Checked == true) { myCurve = myPane.AddCurve("Green", list2, Color.Green, SymbolType.Circle); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // Associate this curve with the Y2 axis myCurve.IsY2Axis = true; } myCurve = myPane.AddCurve("Blue", list3, Color.Blue, SymbolType.Circle); // Fill the symbols with white myCurve.Symbol.Fill = new Fill(Color.White); // Associate this curve with the Y2 axis myCurve.IsY2Axis = true; // Show the x axis grid myPane.XAxis.MajorGrid.IsVisible = true; // Make the Y axis scale red myPane.YAxis.Scale.FontSpec.FontColor = Color.Red; myPane.YAxis.Title.FontSpec.FontColor = Color.Red; // turn off the opposite tics so the Y tics don't show up on the Y2 axis myPane.YAxis.MajorTic.IsOpposite = false; myPane.YAxis.MinorTic.IsOpposite = false; // Don't display the Y zero line myPane.YAxis.MajorGrid.IsZeroLine = false; // Align the Y axis labels so they are flush to the axis myPane.YAxis.Scale.Align = AlignP.Inside; // Manually set the axis range //myPane.YAxis.Scale.Min = -30; //myPane.YAxis.Scale.Max = 30; // Enable the Y2 axis display myPane.Y2Axis.IsVisible = true; // Make the Y2 axis scale blue myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue; myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue; // turn off the opposite tics so the Y2 tics don't show up on the Y axis myPane.Y2Axis.MajorTic.IsOpposite = false; myPane.Y2Axis.MinorTic.IsOpposite = false; // Display the Y2 axis grid lines myPane.Y2Axis.MajorGrid.IsVisible = true; // Align the Y2 axis labels so they are flush to the axis myPane.Y2Axis.Scale.Align = AlignP.Inside; // Fill the axis background with a gradient myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f); //// Add a text box with instructions //TextObj text = new TextObj( // "Zoom: left mouse & drag\nPan: middle mouse & drag\nContext Menu: right mouse", // 0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom ); //text.FontSpec.StringAlignment = StringAlignment.Near; //myPane.GraphObjList.Clear(); //myPane.GraphObjList.Add( text ); // Enable scrollbars if needed zg1.IsShowHScrollBar = true; zg1.IsShowVScrollBar = true; zg1.IsAutoScrollRange = true; zg1.IsScrollY2 = true; // OPTIONAL: Show tooltips when the mouse hovers over a point zg1.IsShowPointValues = true; zg1.PointValueEvent += new ZedGraphControl.PointValueHandler(MyPointValueHandler); // OPTIONAL: Add a custom context menu item zg1.ContextMenuBuilder += new ZedGraphControl.ContextMenuBuilderEventHandler( MyContextMenuBuilder); // OPTIONAL: Handle the Zoom Event zg1.ZoomEvent += new ZedGraphControl.ZoomEventHandler(MyZoomEvent); // Size the control to fit the window SetSize(); // Tell ZedGraph to calculate the axis ranges // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets // up the proper scrolling parameters zg1.AxisChange(); // Make sure the Graph gets redrawn zg1.Invalidate(); }