自定义ZedGraph LineItem的符号类型

时间:2012-08-09 08:59:15

标签: c# .net zedgraph

我绘制了这样的图表

LineItem lineItem = new LineItem("label", pointList, Color.Black, SymbolType.Triangle);
lineItem.Line.IsVisible = _graphLineVisible;
zgc.GraphPane.CurveList.Add(lineItem);

我注意到SymbolType有一个名为UserDefined的枚举元素,有没有办法使用它以及如何使用?

理想情况下,我希望能够实现自己的Symbol并使用它来绘制LineItem,这是可能的,我怎么能继续这样做呢?

2 个答案:

答案 0 :(得分:3)

以下是如何创建自定义向下箭头符号的详细说明,与之前发布的答案一致:

var curve = zgc.GraphPane.AddCurve(null, new[] { 2.1, 2.6, 2.8 }, new[] { 1.8, 1.3, 1.1 }, Color.Blue);

curve.Symbol = new Symbol(SymbolType.UserDefined, Color.Red);
curve.Symbol.UserSymbol = new GraphicsPath(
    new[]
        {
            new PointF(-0.6f, -0.6f), new PointF(-0.6f, 0.6f), new PointF(-1.0f, 0.6f), new PointF(0f, 1.6f), 
            new PointF(1.0f, 0.6f), new PointF(0.6f, 0.6f), new PointF(0.6f, -0.6f),
            new PointF(-0.6f, -0.6f)
        },
    new[]
        {
            (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line,
            (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)PathPointType.Line,
            (byte)PathPointType.Line, (byte)PathPointType.Line
        });

运行此代码将产生以下输出:

Graph with user defined arrow-down symbols

答案 1 :(得分:1)

我想出了如何将自定义符号与LineItem一起使用,具体如下:

Symbol symbol = new Symbol();
symbol.UserSymbol = GetGraphicsPath();
symbol.Size = 5f;

LineItem lineItem = new LineItem("label", pointList, Color.Black, SymbolType.None);     
lineItem.Line.IsVisible = _graphLineVisible; 
lineItem.Symbol = symbol;
zgc.GraphPane.CurveList.Add(lineItem); 

其中GetGraphicsPath()返回一个自定义的GraphicsPath对象,您实际上是使用GraphicsPath.AddLine方法或任何其他方法创建的,具体取决于您想要的符号类型。