// Simple plot with interpolated difference curve private void CreateGraph_DifferencePlot( ZedGraphControl z1 ) { GraphPane myPane = z1.GraphPane; // Generate the first data set PointPairList list1 = new PointPairList(); for ( int i = 0; i < 13; i++ ) { double x = i + 11.0; double y = 150.0 * ( 1.0 + Math.Sin( i * 0.3 ) ); list1.Add( x, y ); } // Generate a second data set that is unrelated to the first PointPairList list2 = new PointPairList(); for ( int i = 0; i < 15; i++ ) { double x = i * 1.2 + 10.0; double y = 250.0 * ( 1.0 + Math.Sin( x * 0.5 ) ); list2.Add( x, y ); } // Make sure the data are sorted and monotonically increasing list1.Sort(); list2.Sort(); // Get the lower and upper limit of the data // This code can throw an exception if either list is empty double xMin = Math.Min( list1[0].X, list2[0].X ); double xMax = Math.Max( list1[list1.Count - 1].X, list2[list2.Count - 1].X ); // Create a new list that will hold the difference points PointPairList diffList = new PointPairList(); // Select the number of points for the new difference curve // This is completely arbitrary, but more points will make it smoother in the // case of SplineInterpolation const int count = 50; // Loop for each data point to be created in the new PointPairList for ( int i=0; i<count; i++ ) { // Calculated X values are evenly spaced double x = xMin + (double) i * ( xMax - xMin ) / count; // Use spline interpolation to create the Y values for the new curve // Note that this allows extrapolation beyond the actual data available // A tension value of 0.5 is used, but anywhere between 0 and 1 is reasonable //double y = list1.InterpolateX( x ); double y1 = list1.InterpolateX( x ); double y2 = list2.SplineInterpolateX( x, 0.5 ); // Add the new Point to the list taking the difference between the Y values // If either value is Missing, it means that a point was extrapolated beyond // the available data, which is not allowed for SplineInterpolateX() // This won't happen with InterpolateX, since it allows extrapolation if ( y1 == PointPair.Missing || y2 == PointPair.Missing ) diffList.Add( x, PointPair.Missing, PointPair.Missing ); else diffList.Add( x, y1 - y2, (y1-y2) > 0 ? 1 : 0 ); } // Create the three curves -- two datasets, plus a difference curve LineItem diffCurve = myPane.AddCurve( "diff", diffList, Color.Red, SymbolType.None ); LineItem myCurve1 = myPane.AddCurve( "curve", list1, Color.Blue, SymbolType.Diamond ); LineItem myCurve2 = myPane.AddCurve( "curve 2", list2, Color.Green, SymbolType.Circle ); Color[] colors = { Color.Red, Color.Green }; diffCurve.Line.Fill = new Fill( colors, 90 ); diffCurve.Line.Fill.RangeMin = 0; diffCurve.Line.Fill.RangeMax = 1; diffCurve.Line.Fill.Type = FillType.GradientByZ; //diffCurve.Line.GradientFill = new Fill( colors, 90 ); //diffCurve.Line.GradientFill.RangeMin = -100; //diffCurve.Line.GradientFill.RangeMax = 200; //diffCurve.Line.IsOptimizedDraw = true; // Add some "pretty" stuff (optional) myCurve1.Symbol.Fill = new Fill( Color.White ); myCurve2.Symbol.Fill = new Fill( Color.White ); diffCurve.Line.Width = 2.0f; //diffCurve.Symbol.Fill = new Fill( Color.White ); myPane.Title.Text = "Interpolated Data Curve"; myPane.XAxis.Title.Text = "Period"; myPane.YAxis.Title.Text = "Response"; myPane.Legend.FontSpec.Size = 14; myPane.Fill = new Fill( Color.WhiteSmoke, Color.Lavender, 0F ); myPane.Chart.Fill = new Fill( Color.FromArgb( 255, 255, 245 ), Color.FromArgb( 255, 255, 190 ), 90F ); XDate xx = new XDate( 2007, 11, 9 ); XDate x2 = new XDate( 2007, 11, 9 ); XDate x3 = new XDate( 2007, 11, 9, 1, 1, 1 ); object junk = new object(); int i1 = xx.CompareTo( xx ); int i2 = xx.CompareTo( x2 ); int i3 = xx.CompareTo( x3 ); int i4 = x2.CompareTo( xx ); int i5 = x2.CompareTo( x3 ); int i6 = x3.CompareTo( x2 ); int i7 = x3.CompareTo( junk ); z1.IsAntiAlias = true; z1.AxisChange(); }