You can show lines with alternating colors by painting the line twice:
-
Paint it using a solid line style in one color.
-
Use a dashed line style in the other color to paint it the second time around.
You paint a line twice by configuring two painters on the layer. For example:
//To have alternating colors, we will paint a solid line and on top of it a dashed line in another color
//First we define both the solid and dashed line style
Color solidLineColor = Color.BLUE;
TLcdStrokeLineStyle solidLineStyle = TLcdStrokeLineStyle.newBuilder().color(solidLineColor).lineWidth(lineWidth).build();
Color dashedLineColor = Color.ORANGE;
TLcdStrokeLineStyle dashedLineStyle = TLcdStrokeLineStyle.newBuilder().dashedLineStyle(20f).lineWidth(lineWidth).color(dashedLineColor).build();
//Then we create the painters configured with those styles
TLcdGXYShapePainter solidLinePainter = new TLcdGXYShapePainter();
solidLinePainter.setLineStyle(solidLineStyle);
TLcdGXYShapePainter dashedLinePainter = new TLcdGXYShapePainter();
dashedLinePainter.setLineStyle(dashedLineStyle);
//Finally, create the layer and configure both painters on it
TLcdGXYLayer layer = TLcdGXYLayer.create(model);
layer.setGXYPainterProviderArray(new ILcdGXYPainterProvider[]{solidLinePainter, dashedLinePainter});
which results in:
Other examples of cases for using an array of painter providers are: