Ashitakalax
Ashitakalax

Reputation: 1557

C# Zedgraph Change Line Dash Length

I'm trying to change the length of the Dashes on the Zed Graph line. I would like to have larger gaps between the solid lines.

example of my code

LineItem LineCurve = null
LineCurve = ZedGraphControl.GraphPane.AddCurve("line1",PairPointListData, Color, Symbol);
//now I want to change the dash settings
LineCurve.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
LineCurve.Line.StepType = StepType.ForwardStep;
LineCurve.Line.DashOn = 1.0f;//Not sure what this floating point does
LineCurve.Line.DashOff = 1.0f;//Also not sure

I have changed the values of the Dash On and Off, but I can't see anything noticeable.

Upvotes: 2

Views: 6966

Answers (1)

Gordon Slysz
Gordon Slysz

Reputation: 1143

Your dash style must be set to 'Custom'. See: http://zedgraph.sourceforge.net/documentation/html/P_ZedGraph_LineBase_DashOff.htm

Here is some sample code:

        double[] xvals = new double[100];
        double[] yvals = new double[100];

        for (double i = 0; i < xvals.Length; i++)
        {
            xvals[(int)i] = i / 10;
            yvals[(int)i] = Math.Sin(i / 10);
        }

        var zgc = msGraphControl1.zedGraphControl1;
        var lineItem = zgc.GraphPane.AddCurve("Custom", xvals, yvals, Color.Blue);

        lineItem.Line.Style = DashStyle.Custom;
        lineItem.Line.Width = 3;
        lineItem.Line.DashOn = 5;
        lineItem.Line.DashOff = 10;

        //offset the next curve
        for (int i = 0; i < xvals.Length; i++)
        {
            xvals[i] = xvals[i] + 0.5;
            yvals[i] = yvals[i] + 0.05;
        }

        var lineItem2 = zgc.GraphPane.AddCurve("DashDotDot", xvals, yvals, Color.Red);

        lineItem2.Line.Width = 3;
        lineItem2.Line.Style = DashStyle.DashDotDot;

        //offset the next curve
        for (int i = 0; i < xvals.Length; i++)
        {
            xvals[i] = xvals[i] + 0.5;
            yvals[i] = yvals[i] + 0.05;
        }

        var lineItem3 = zgc.GraphPane.AddCurve("Solid", xvals, yvals, Color.Black);

        lineItem3.Line.Width = 3;
        lineItem3.Line.Style = DashStyle.Solid;


        zgc.AxisChange();
        zgc.Refresh();

Upvotes: 8

Related Questions