2017-04-20 1 views
0

普通のLineAndPointRendererを使用すると、すべての凡例アイコンが正常に表示されます。「FastLineAndPointRenderer」を使用しているときは、散布図の凡例アイコンは空白です

//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

たぶん私はこれを行うには、いくつかの簡単な方法を逃しました。もしそうなら、別の回答を投稿してください。それ以外の場合は、クラスを拡張し、頂点キャンバスをペイントするコードを追加すると、私のために働きました:

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; 
} 
+0

「FastLineAndPointRenderer」実装のバグのようです。それを追跡するために[このレポート](https://github.com/halfhp/androidplot/issues/39)を作成しました。次のリリースで修正されます。上のあなたのアプローチは、中間の良い解決策のように見えます。 – Nick

関連する問題