Search code examples
androidandroid-widgetgraphingandroidplot

AndroidPlot: Support for graphing a dashed line


Are there line styles in the works for dashed lines, dotted lines, etc.?

I know you can add/remove the point by setting the vertexColor to null like in this example:

LineAndPointFormatter blueFormat = new LineAndPointFormatter(Color.rgb(30,144,255), null, null);

however, I haven't been able to find a quick property setting like "setDottedLine(true)" or something to that extent in the javadoc. I suppose I could graph every 10 points and drop every 10 while I'm parsing, but that might be a little more overhead than needed.

Is there a work around or a trick to create a dashed line using LineAndPointFormatter or by setting some other widget property?


Solution

  • Figured it out..

    There is a constructor for LineAndPointFormatter:

    setLinePaint(Paint)

    So to draw a dashed line, you would then use a snippet like this:

    Paint dashPaint = new Paint();
    dashPaint.setColor(getResources().getColor(R.color.red));
    dashPaint.setStyle(Paint.Style.STROKE);
    dashPaint.setStrokeWidth(3);
    dashPaint.setPathEffect(new DashPathEffect(new float[] {10,5}, 0));
    LineAndPointFormatter redDash = new LineAndPointFormatter(dashPaint.getColor(), null, null);
    redDash.setLinePaint(dashPaint);
    plot.addSeries(red,redDash);
    plot.redraw();