2011-12-06 3 views
0

私はzedgraphでスタックバーを作ろうとしています。私はこのサイトの質問にあるコード例を使用しました。私はいくつかの変更を加えましたが、私が望むように働くことはできません。グラフ上の出力は、互いに積み重ねられた棒です。メソッドが2回目に実行されると、初めてのバーはまだ存在し、新しいバーは古いバーの上に構築されます。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(); 

ご理解ください。 GPRは、必要なサイズとタイトル文字列を使用して(新しい)長方形であることを

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

;:私は

+0

このサイトをご覧ください:http://www.codeproject.com/KB/graphics/zedgraph.aspx – Moonlight

+0

私は以前このサイトを見てきましたが、私は何も見つけられませんでした - 私は思います:) – WildBoar

+0

それを見て、あなたが必要とするものを見つけました。 – Moonlight

答えて

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(); 
    } 
+0

ありがとう、私はそれについて作業します。多くの助けになります! – WildBoar

0

(1)Zedgraphプロジェクトは、私はいつものように何かをしました

関連する問題