使用“FastLineAndPointRenderer”时,散点图图例图标为空白

时间:2017-04-20 22:29:39

标签: androidplot

当我使用常规LineAndPointRenderer时,我的所有传奇图标都会正常显示。

//works but is slow
private LineAndPointFormatter getScatterPlotFormatter() {
    LineAndPointFormatter formatter = new LineAndPointFormatter(
            Color.TRANSPARENT,
            Color.argb(0xFF, mRandom.nextInt(0xFF), mRandom.nextInt(0xFF), mRandom.nextInt(0xFF)),
            null,
            null
    );
    formatter.getVertexPaint().setStrokeWidth(getContext().getResources().getDimension(R.dimen.chart_vertex_size));
    return formatter;
}

legend working correctly

documentation建议我使用FastLineAndPointRenderer,但是当我这样做时,图例图标显示为空白。这只影响我的散点图。

//does not show proper legend icon
private LineAndPointFormatter getScatterPlotFormatter() {
    FastLineAndPointRenderer.Formatter formatter = new FastLineAndPointRenderer.Formatter(
            Color.TRANSPARENT,
            Color.argb(0xFF, mRandom.nextInt(0xFF), mRandom.nextInt(0xFF), mRandom.nextInt(0xFF)),
            null
    );
    formatter.getVertexPaint().setStrokeWidth(getContext().getResources().getDimension(R.dimen.chart_vertex_size));
    return formatter;
}

missing legend icon

1 个答案:

答案 0 :(得分:1)

也许我错过了一些更简单的方法来做到这一点。如果是,请发布另一个答案。否则,扩展类并添加代码以绘制顶点画布为我工作:

public static class FastScatterChartRenderer extends FastLineAndPointRenderer {
    public FastScatterChartRenderer(XYPlot plot) {
        super(plot);
    }

    @Override
    protected void doDrawLegendIcon(Canvas canvas,
                                    RectF rect,
                                    Formatter formatter) {
        super.doDrawLegendIcon(canvas, rect, formatter);
        if(formatter.hasVertexPaint()) {
            canvas.drawPoint(rect.centerX(), rect.centerY(), formatter.getVertexPaint());
        }
    }
}

@NonNull
private LineAndPointFormatter getScatterPlotFormatter() {
    FastLineAndPointRenderer.Formatter formatter = new FastLineAndPointRenderer.Formatter(
            null,
            Color.argb(0xFF, mRandom.nextInt(0xFF), mRandom.nextInt(0xFF), mRandom.nextInt(0xFF)),
            null
    ){
        @Override
        public Class<? extends SeriesRenderer> getRendererClass() {
            return FastScatterChartRenderer.class;
        }

        @Override
        public SeriesRenderer doGetRendererInstance(XYPlot plot) {
            return new FastScatterChartRenderer(plot);
        }
    };
    formatter.getVertexPaint().setStrokeWidth(getContext().getResources().getDimension(R.dimen.chart_vertex_size));
    return formatter;
}