如何在zedgraph中绘制条形曲线,其中条形线彼此相邻?

时间:2019-09-12 09:45:31

标签: c# zedgraph

我想从条形图上绘制一条曲线,条形图从(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。

在测试项目中,我使用了BoxObj对象,这些对象已添加到GraphPane的GraphObjList

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对象。

1 个答案:

答案 0 :(得分:0)

解决方案非常简单,找到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;允许选择如何连接曲线的点。

相关问题