ysm
ysm

Reputation: 11

How can I display a ZedGraph on the screen?

I need to draw graphics for my project so I searched zedgraph library.I looked at this sample codes for learning that library. But I can't display the graphics on the screen. Plese help me. Here is the code.

namespace gafikdeneme
{
    class Program
    {
        static void Main(string[] args)
        {

            GraphPane pane = new GraphPane();

        pane.CurveList.Clear ();

        PointPairList list1 = new PointPairList ();
        PointPairList list2 = new PointPairList ();
        PointPairList list3 = new PointPairList ();

        double xmin = -50;
        double xmax = 50;

        for (double x = xmin; x <= xmax; x += 0.01)
        {
            list1.Add (x, f1 (x));
            list2.Add (x, f2 (x));
            list3.Add (x, f3 (x));
        }

        pane.YAxisList.Clear ();

        int axis1 = pane.AddYAxis ("Axis 1");
        int axis2 = pane.AddYAxis ("Axis 2");
        int axis3 = pane.AddYAxis ("Axis 3");           


        LineItem myCurve1 = pane.AddCurve ("Curve 1", list1, Color.Blue, SymbolType.None);
        LineItem myCurve2 = pane.AddCurve ("Curve 2", list2, Color.Black, SymbolType.None);
        LineItem myCurve3 = pane.AddCurve ("Curve 3", list3, Color.Red, SymbolType.None);


        myCurve1.YAxisIndex = axis1;
        myCurve2.YAxisIndex = axis2;
        myCurve3.YAxisIndex = axis3;

        myCurve1.IsVisible = true;
        myCurve2.IsVisible = true;
        myCurve3.IsVisible = true;

        pane.YAxisList[axis1].Title.FontSpec.FontColor = Color.Blue;
        pane.YAxisList[axis2].Title.FontSpec.FontColor = Color.Black;
        pane.YAxisList[axis3].Title.FontSpec.FontColor = Color.Red;

        pane.AxisChange();
 }

   public static double f1 (double x)
    {
        if (x == 0)
        {
            return 1;
        }

        return Math.Sin (x) / x;
    }

   public static  double f2(double x)
    {
        if (x == 0)
        {
            return 1;
        }

        return 10 * Math.Sin (x * 0.5) / x;
    }


   public static double f3(double x)
    {
        if (x == 0)
        {
            return 1;
        }

        return 0.1 * Math.Sin (x * 2) / x;
    }

        }
    }

Upvotes: 0

Views: 564

Answers (1)

koponk
koponk

Reputation: 472

maybe this will fix your problem

//litle change here
ZedGraphControl control = new ZedGraph.ZedGraphControl();
GraphPane pane = control.GraphPane;
//--

pane.CurveList.Clear ();

PointPairList list1 = new PointPairList ();
PointPairList list2 = new PointPairList ();
PointPairList list3 = new PointPairList ();

double xmin = -50;
double xmax = 50;

for (double x = xmin; x <= xmax; x += 0.01)
{
    list1.Add (x, f1 (x));
    list2.Add (x, f2 (x));
    list3.Add (x, f3 (x));
}

pane.YAxisList.Clear ();

int axis1 = pane.AddYAxis ("Axis 1");
int axis2 = pane.AddYAxis ("Axis 2");
int axis3 = pane.AddYAxis ("Axis 3");           


LineItem myCurve1 = pane.AddCurve ("Curve 1", list1, Color.Blue, SymbolType.None);
LineItem myCurve2 = pane.AddCurve ("Curve 2", list2, Color.Black, SymbolType.None);
LineItem myCurve3 = pane.AddCurve ("Curve 3", list3, Color.Red, SymbolType.None);


myCurve1.YAxisIndex = axis1;
myCurve2.YAxisIndex = axis2;
myCurve3.YAxisIndex = axis3;

myCurve1.IsVisible = true;
myCurve2.IsVisible = true;
myCurve3.IsVisible = true;

pane.YAxisList[axis1].Title.FontSpec.FontColor = Color.Blue;
pane.YAxisList[axis2].Title.FontSpec.FontColor = Color.Black;
pane.YAxisList[axis3].Title.FontSpec.FontColor = Color.Red;

pane.AxisChange();

//and here, we have panel(panel1) to show our graph
this.panel1.Controls.Add(control);
//--

Upvotes: 2

Related Questions