如何在 zedgraph 中绘制一条条形曲线,其中条形图彼此相邻?
How to draw a bar curve in zedgraph where the bars are next to each other?
我想用条形图画一条曲线,条形图从 (x,0) 的左下角开始向上延伸到 (x,y),宽度取决于下一个曲线点的开始位置
鉴于以下几点:
X Y
0 3
1 4
3 2
我想从
绘制柱状图
(0,3) to (1,3)
(1,4) to (3,4)
(3,2) to (4,2)
最后一个条的宽度可以是常量或 0。
在我的测试项目中,我使用了添加到 GraphPane 的 GraphObjList
的 BoxObj
个对象:
private void Form1_Shown(object sender, EventArgs e)
{
// Make some sample data points
PointF[] p = new PointF[360];
for (int i = 0; i < p.Length; i++)
{
p[i] = new PointF(i,(float) Math.Sin(i * (Math.PI *2 )/360));
}
// 2 Curves, with different interpolations of their values
for (int i = 0; i < p.Length; i++)
{
// Left point extends to the next point
ppl.Add(p[i].X, p[i].Y);
if (i+1 < p.Length)
ppl.Add(p[i+1].X, p[i].Y);
// Right point extends to the previous point
if (i> 0)
ppl1.Add(p[i- 1].X, p[i].Y);
ppl1.Add(p[i].X, p[i].Y);
}
// Box objects like the curve of ppl, negative values still need to be corrected
for (int i = 0; i < p.Length-1; i++)
{
BoxObj b = new BoxObj(p[i].X, p[i].Y, p[i+1].X-p[i].X, p[i].Y);
b.IsClippedToChartRect = true;
b.Fill = new Fill(Brushes.PapayaWhip);
zedGraphControl1.GraphPane.GraphObjList.Add(b);
}
ZedGraph.CurveItem neueKurve = zedGraphControl1.GraphPane.AddCurve("+1",ppl , Color.Blue);
ZedGraph.CurveItem neueKurve1 = zedGraphControl1.GraphPane.AddCurve("-1",ppl1 , Color.Green);
ZedGraph.BarSettings bs = new ZedGraph.BarSettings(zedGraphControl1.GraphPane);
bs.Type = ZedGraph.BarType.Stack;
zedGraphControl1.GraphPane.AxisChange();
zedGraphControl1.PerformAutoScale();
zedGraphControl1.Invalidate();
}
这可行,但框对象的组织方式不像 CurveItem 对象。
解决方法很简单,找到zedgraph库的源码后就出来了这个
ZedGraph.LineItem neueKurve = new LineItem("+1", ppl, Color.Blue, SymbolType.None);
ZedGraph.LineItem neueKurve1 = new LineItem("+2", ppl1, Color.Green, SymbolType.None);
neueKurve.Line.StepType = StepType.ForwardSegment;
neueKurve.Line.Fill.Type = FillType.Brush;
neueKurve.Line.Fill.Brush = SystemBrushes.Info;
neueKurve1.Line.StepType = StepType.RearwardSegment;
zedGraphControl1.GraphPane.CurveList.Add(neueKurve);
zedGraphControl1.GraphPane.CurveList.Add(neueKurve1);
Line.StepType = StepType.RearwardSegment;
允许 select 曲线点的连接方式。
我想用条形图画一条曲线,条形图从 (x,0) 的左下角开始向上延伸到 (x,y),宽度取决于下一个曲线点的开始位置
鉴于以下几点:
X Y
0 3
1 4
3 2
我想从
绘制柱状图(0,3) to (1,3)
(1,4) to (3,4)
(3,2) to (4,2)
最后一个条的宽度可以是常量或 0。
在我的测试项目中,我使用了添加到 GraphPane 的 GraphObjList
的 BoxObj
个对象:
private void Form1_Shown(object sender, EventArgs e)
{
// Make some sample data points
PointF[] p = new PointF[360];
for (int i = 0; i < p.Length; i++)
{
p[i] = new PointF(i,(float) Math.Sin(i * (Math.PI *2 )/360));
}
// 2 Curves, with different interpolations of their values
for (int i = 0; i < p.Length; i++)
{
// Left point extends to the next point
ppl.Add(p[i].X, p[i].Y);
if (i+1 < p.Length)
ppl.Add(p[i+1].X, p[i].Y);
// Right point extends to the previous point
if (i> 0)
ppl1.Add(p[i- 1].X, p[i].Y);
ppl1.Add(p[i].X, p[i].Y);
}
// Box objects like the curve of ppl, negative values still need to be corrected
for (int i = 0; i < p.Length-1; i++)
{
BoxObj b = new BoxObj(p[i].X, p[i].Y, p[i+1].X-p[i].X, p[i].Y);
b.IsClippedToChartRect = true;
b.Fill = new Fill(Brushes.PapayaWhip);
zedGraphControl1.GraphPane.GraphObjList.Add(b);
}
ZedGraph.CurveItem neueKurve = zedGraphControl1.GraphPane.AddCurve("+1",ppl , Color.Blue);
ZedGraph.CurveItem neueKurve1 = zedGraphControl1.GraphPane.AddCurve("-1",ppl1 , Color.Green);
ZedGraph.BarSettings bs = new ZedGraph.BarSettings(zedGraphControl1.GraphPane);
bs.Type = ZedGraph.BarType.Stack;
zedGraphControl1.GraphPane.AxisChange();
zedGraphControl1.PerformAutoScale();
zedGraphControl1.Invalidate();
}
这可行,但框对象的组织方式不像 CurveItem 对象。
解决方法很简单,找到zedgraph库的源码后就出来了这个
ZedGraph.LineItem neueKurve = new LineItem("+1", ppl, Color.Blue, SymbolType.None);
ZedGraph.LineItem neueKurve1 = new LineItem("+2", ppl1, Color.Green, SymbolType.None);
neueKurve.Line.StepType = StepType.ForwardSegment;
neueKurve.Line.Fill.Type = FillType.Brush;
neueKurve.Line.Fill.Brush = SystemBrushes.Info;
neueKurve1.Line.StepType = StepType.RearwardSegment;
zedGraphControl1.GraphPane.CurveList.Add(neueKurve);
zedGraphControl1.GraphPane.CurveList.Add(neueKurve1);
Line.StepType = StepType.RearwardSegment;
允许 select 曲线点的连接方式。