tnkrosh - 2007-05-21

A curve is to be plotted from x=-2 to +2 but has to be shaded (filled) partially between x=0 to x=1. In the following code, I have apprarently achieved this goal.

I first plotted the curve for x=-2 to +2 using standard procedure but without filling. To achieve the second part of the goal (partial filling), I re-plotted the curve again from x=0 to 1 but this time I applied the Fill property.

Is this a correct method? Or is there any other elegant way?
Or is there any in-built method in the LineItem class that I am not able to see?

using System;
using System.Drawing;
using ZedGraph;
using ZedGraph.Web; // ver 5.0.6

namespace ZG1 {
public partial class graph : System.Web.UI.Page {

      public static double f(double x) {
        return Math.Exp(-(x * x)); //function to be integrated and plotted
      }

    override protected void OnInit(EventArgs e) {
        ZedGraphWeb1.RenderGraph += new ZedGraphWebControlEventHandler(this.OnRenderGraph);
    }
    private void OnRenderGraph(ZedGraphWeb zgw, Graphics g, MasterPane mPane) {

        GraphPane myPane = mPane[0];

        myPane.Border.IsVisible = false; // default is true
        myPane.XAxis.Title.Text = "x ";
        myPane.XAxis.MajorGrid.IsZeroLine = true;
        myPane.XAxis.MinorTic.Size = 0;
        myPane.YAxis.Title.Text = "y";
        myPane.YAxis.MinorTic.Size = 0;

        //Plot the curve from -2 to +2
        PointPairList list1 = new PointPairList();
        for (double x = -2; x <= +2; x += 0.1) list1.Add(x, f(x));
        LineItem myCurve1 = myPane.AddCurve("y = f(x) = exp(-(x^2))", list1, Color.Blue, SymbolType.None);
        //---------------------

        //Shade (Fill) the area between 0 to 1
        PointPairList list2 = new PointPairList();
        for (double x = 0; x <= 1; x += 0.1) list2.Add(x, f(x));
        LineItem myCurve2 = myPane.AddCurve(null, list2, Color.Blue, SymbolType.None);
        myCurve2.Line.Fill = new Fill(Color.White, Color.Gray, 45F);
        //--------------------------------------------

        myPane.AxisChange(g);
    }
}

}