質問

I'm trying to add a dashline for a graph but it keeps coming out as a solid line. How can I fix that?

static public NPlot.Bitmap.PlotSurface2D getDashlineGraph(int itemID, int width, int height)
{
    NPlot.Bitmap.PlotSurface2D plot = new NPlot.Bitmap.PlotSurface2D(width, height);
    plot.BackColor = Color.WhiteSmoke;
    plot.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

    LinePlot TotaldashLine = new LinePlot(straightline, timer);     
    float[] pattern = { 5.0f, 10.0f };
    TotaldashLine.Pen = new Pen(Color.Green,0.5f);
    TotaldashLine.Pen.DashPattern = pattern;       
    plot.Add(TotaldashLine, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Right, 100);

    Grid oGrid = new Grid();
    oGrid.HorizontalGridType = Grid.GridType.Coarse;
    oGrid.VerticalGridType = Grid.GridType.Coarse;
    plot.Add(oGrid);       
     plot.Refresh();
    return plot;

}

役に立ちましたか?

解決

You need to specify that you want your Pen to draw dashed using Pen.DashStyle:

TotaldashLine.Pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

Once you have done that, you can additionally customize the lengths of dashes and gaps using the Pen.DashPattern as you have.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top