Zedgraph,不止一根柱
我正在尝试用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我做的(一个)Zedgraph 项目,我总是做类似的事情:
gpr 是一个(新)矩形,具有所需的大小和标题字符串;
The (one) Zedgraph project I did, I always did something like:
with gpr being a (new) Rectangle with the required size and title a string;