Last active
March 3, 2020 14:45
-
-
Save Phlip/81f37c255f9582d5f92e38980e0f44db to your computer and use it in GitHub Desktop.
fix bug in AChartEngine's legend, where the sample line didn't pick up its series's Stroke setting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
AChartEngine has a bug. In a Series, such as an XYSeries or TimeSeries, if you set a Stroke, | |
such as myXYRenderer.setStroke(BasicStroke.DASHED), the line appears dashed. But the sample line | |
down in the legend, while the correct color, is not dashed. | |
The fix is to get into LineChart.java and make drawLegendShape() look a little bit like this: | |
*/ | |
public void drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y, | |
int seriesIndex, Paint paint) { | |
float oldWidth = paint.getStrokeWidth(); | |
float lineWidth = ((XYSeriesRenderer) renderer).getLineWidth(); | |
PathEffect formerEffect = paint.getPathEffect(); | |
if (lineWidth > 0.0) { | |
paint.setStrokeWidth(lineWidth); | |
BasicStroke stroke = renderer.getStroke(); | |
if (stroke == null) | |
stroke = BasicStroke.SOLID; | |
PathEffect effect = null; | |
if (stroke.getIntervals() != null) { | |
effect = new DashPathEffect(stroke.getIntervals(), stroke.getPhase()); | |
} | |
paint.setStrokeCap(stroke.getCap()); | |
paint.setStrokeJoin(stroke.getJoin()); | |
paint.setStrokeMiter(stroke.getMiter()); | |
paint.setPathEffect(effect); | |
paint.setStyle(Style.FILL_AND_STROKE); | |
canvas.drawLine(x, y, x + SHAPE_WIDTH, y, paint); | |
} | |
paint.setStrokeWidth(oldWidth); | |
if (isRenderPoints(renderer)) { | |
pointsChart.drawLegendShape(canvas, renderer, x + 5, y, seriesIndex, paint); | |
} | |
paint.setPathEffect(formerEffect); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment