Androidplot 使用“FastLineAndPointRenderer”时,散点图图例图标为空`
当我使用常规的Androidplot 使用“FastLineAndPointRenderer”时,散点图图例图标为空`,androidplot,Androidplot,当我使用常规的LineAndPointRenderer时,我所有的图例图标都会正常显示 //works but is slow private LineAndPointFormatter getScatterPlotFormatter() { LineAndPointFormatter formatter = new LineAndPointFormatter( Color.TRANSPARENT, Color.argb(0xFF, mRa
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;
}
建议改用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;
}
也许我错过了一些更简单的方法。如果是,请发布另一个答案。否则,扩展该类并添加代码以绘制顶点画布对我来说很有用:
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;
}
公共静态类FastScatterChartRenderer扩展了FastLineAndPointRenderer{
公共FastScatterChartRenderer(XYPlot){
超级(情节);
}
@凌驾
受保护的void doDrawLegendIcon(画布,
rectfrect,
格式化程序(格式化程序){
super.doDrawLegendIcon(canvas、rect、formatter);
if(formatter.hasVertexPaint()){
drawPoint(rect.centerX(),rect.centerY(),formatter.getVertexPaint());
}
}
}
@非空
private LineAndPointFormatter getScatterPlotFormatter(){
FastLineAndPointRenderer.Formatter Formatter=新的FastLineAndPointRenderer.Formatter(
无效的
Color.argb(0xFF,mRandom.nextInt(0xFF),mRandom.nextInt(0xFF),mRandom.nextInt(0xFF)),
无效的
){
@凌驾
public类在FastLineAndPointRenderer
实现中看起来像个bug。我创建它是为了跟踪它-将在下一个版本中修复。您上面的方法看起来是一个不错的解决方案。