Search code examples
c#.netzedgraph

Customize symbol type of a ZedGraph LineItem


I plot a graph like this

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

I notice that SymbolType have an enum element called UserDefined, is there a way to use this and how?

Ideally I would want to be able to implement my own Symbol and use it to draw a LineItem, is this possible and how could I go on about doing this?


Solution

  • Here is a detailed illustration of how to create custom arrow-down symbols, in line with the previously published answer:

    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
            });
    

    Running this code would yield the following output:

    Graph with user defined arrow-down symbols