Zedgraph,不止一个吧

时间:2011-12-06 15:56:31

标签: c# visual-studio-2010 zedgraph

我正在尝试用zedgraph制作一个堆叠条。我在本网站的一个问题中使用了一些编码示例。我做了一些改变,但我无法让我按照自己的意愿工作。图表上的输出是相互堆叠的条形图。当方法第二次运行时,第一次的条形图仍然存在,而新的条形图则建立在旧条形图之上。

想要的输出:我希望在列表中看到每个整数的堆叠条。但它必须是这样的,listA中的第一个整数与listB中的第一个整数在同一个条上。

        zedGraphControl1.GraphPane.CurveList.Clear();
        zedGraphControl1.GraphPane.GraphObjList.Clear();
        //I want to clear my chart, and write a new one. I dont think the above works??^^^

        GraphPane myPane = zedGraphControl1.GraphPane;

        myPane.BarSettings.Type = BarType.PercentStack;
        myPane.XAxis.Type = ZedGraph.AxisType.Date;

        PointPairList PPLa = new PointPairList();
        PointPairList PPLb = new PointPairList();
        PointPairList PPLc = new PointPairList();
        PointPairList PPLd = new PointPairList();
        PointPairList PPLf = new PointPairList();
        List<int> listA = new List<int>();
        List<int> listB = new List<int>();
        List<int> listC = new List<int>();
        List<int> listD = new List<int>();
        List<int> listF = new List<int>();
        listA = getIntA()
        listB = getIntB()
        listC = getIntC()
        listD = getIntD()
        listF = getIntF()

        int Max = listA.Count;
        //^^ I've made this line to control how many times the loop should run.

        for (int i = 0; i < Max; i++)
        {
            DateTime dtime = DateTime.Now;
            double date = (double)new XDate(dtime);

            int som1;
            for(som1 = 0; som1 <= (listA.Count - 1); som1++)
            {
                int a = listA[i];
                PPLa.Add(date, (double)a);

            }

            int som2;
            for (som2 = 0; som2 <= (listB.Count - 1); som2++)
            {
                int b = listB[i];
                PPLb.Add(date, (double)b);

            }

            int som3;
            for (som3 = 0; som3 <= (listC.Count - 1); som3++)
            {
                int c = listC[i];
                PPLc.Add(date, (double)c);

            }

            int som4;
            for (som4 = 0; som4 <= (listD.Count - 1); som4++)
            {
                int d = listD[i];
                PPLd.Add(date, (double)d);

            }

            int som5;
            for (som5 = 0; som5 <= (listF.Count - 1); som5++)
            {
                int f = listF[i];
                PPLf.Add(date, (double)f);

            }



            BarItem myBara = myPane.AddBar("A", PPLa, Color.Red);
            BarItem myBarb = myPane.AddBar("B", PPLb, Color.Blue);
            BarItem myBarc = myPane.AddBar("C", PPLc, Color.Gray);
            BarItem myBard = myPane.AddBar("D", PPLd, Color.Black);
            BarItem myBarf = myPane.AddBar("F", PPLf, Color.Pink);


            zedGraphControl1.AxisChange();



        }
        zg1.AxisChange();

希望你理解。

2 个答案:

答案 0 :(得分:0)

    private void graph2()
    {
        zedGraphControl1.GraphPane.CurveList.Clear();
        zedGraphControl1.GraphPane.GraphObjList.Clear();
        // clearing not tested

        GraphPane myPane = zedGraphControl1.GraphPane;

        myPane.BarSettings.Type = BarType.PercentStack;
        //      myPane.XAxis.Type = ZedGraph.AxisType.Date;
        // Date wont work in our case

        PointPairList PPLa = new PointPairList();
        PointPairList PPLb = new PointPairList();
        PointPairList PPLc = new PointPairList();
        PointPairList PPLd = new PointPairList();
        PointPairList PPLf = new PointPairList();
        List<int> listA = new List<int>();
        List<int> listB = new List<int>();
        List<int> listC = new List<int>();
        List<int> listD = new List<int>();
        List<int> listF = new List<int>();
        //listA = getIntA();
        //listB = getIntB();
        //listC = getIntC();
        //listD = getIntD();
        //listF = getIntF();

        for (int i = 0; i < 5; i++)
        {
            listA.Add(i);
            listB.Add(i + 1);
            listC.Add(i);
        }
        // above is used to fill up the lists (for example)
        // be aware that listA[0] = 0 for i = 1, (will be vissible in chart)


        // when you us < instead of <= you dont need a listA.Count - 1
        // below is not failsafe, if any list is smaller than listA an error may appear
        // this is just a sample so i thought it wouldnt matter
        for (int i = 0; i < listA.Count; i++)
        {
            PPLa.Add(i, (double)listA[i]);
            PPLb.Add(i, (double)listB[i]);
            PPLc.Add(i, (double)listC[i]);
            PPLd.Add(i, (double)listA[i]);
            PPLf.Add(i, (double)listB[i]);
        }

        // dragged drawing baritems out of forloop
        BarItem myBara = myPane.AddBar("A", PPLa, Color.Red);
        BarItem myBarb = myPane.AddBar("B", PPLb, Color.Blue);
        BarItem myBarc = myPane.AddBar("C", PPLc, Color.Gray);
        BarItem myBard = myPane.AddBar("D", PPLd, Color.Black);
        BarItem myBarf = myPane.AddBar("F", PPLf, Color.Pink);

        zedGraphControl1.AxisChange();
    }

答案 1 :(得分:0)

我做过的(一个)Zedgraph项目,我总是这样做:

master = zedGraphDruck.MasterPane;
master.GraphObjList.Clear();
master.PaneList.Clear();
GraphPane g = new GraphPane(gpr, titel, null, null);
...
master.Add(g);
zedGraphDruck.AxisChange();
zedGraphDruck.Invalidate();

gpr是一个(新的)矩形,所需的大小和标题是一个字符串;