如何在屏幕上显示ZedGraph?

时间:2013-01-02 08:35:16

标签: zedgraph

我需要为我的项目绘制图形,所以我搜索了zedgraph库。我查看了这个示例代码来学习该库。但我无法在屏幕上显示图形。请帮助我。这是代码。

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;
    }

        }
    }

1 个答案:

答案 0 :(得分:2)

也许这会解决你的问题

//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);
//--