Zedgraph,不止一根柱

发布于 2024-12-19 22:58:29 字数 2925 浏览 1 评论 0原文

我正在尝试用 zedgraph 制作一个 stackedbar 。我使用了在本网站的一个问题中找到的一些编码示例。我做了一些改变,但我无法让我按照我想要的方式工作。图表上的输出是相互堆叠的条形。当该方法第二次运行时,第一次的柱仍然存在,并且新的柱构建在旧柱的顶部。

想要的输出:我想看到列表中每个整数的堆积条。但必须确保 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();

希望你理解。

I'm trying to make a stackedbar with zedgraph. I've used some coded example founded in a question on this site. I'v made some changes, but I can't get i to work as I want. The output on the chart are bars stacked over each other. And when the method are runs second time, the bars from the first time are still there, and the new ones are built on top of the old bars.

The wanted output: I want to see a stackedbar for every integer I have in my list. But it must be such that the first integer in listA is on the same bar as the first from 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();

Hope you understand.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软甜啾 2024-12-26 22:58:29
    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();
    }
    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();
    }
不交电费瞎发啥光 2024-12-26 22:58:29

我做的(一个)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 是一个(新)矩形,具有所需的大小和标题字符串;

The (one) Zedgraph project I did, I always did something like:

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

with gpr being a (new) Rectangle with the required size and title a string;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文