Search code examples
javaandroidandroidplot

AndroidPlot: XYPlot How to make Bars with rounded corners


I am working with AndroidPlot since about one year to display different Diagrams in my app. Now I am working with BarCharts, the charts are finished but how can I make corners rounded?

I found some results for lines: How to make line with rounded (smooth) corners with AndroidPlot

I tried already:

BarFormatter formatter1,formatter2, formatter3;
formatter1.getBorderPaint().setStrokeJoin(Paint.Join.ROUND);
formatter1.getFillPaint().setStrokeJoin(Paint.Join.ROUND);

doesn't seems to have any impact.

then I tried:

XYPlot plot; //Initialized with UI-Diagrammm above
...
plot.setBorderStyle(XYPlot.BorderStyle.ROUNDED,5f,5f);

Does anyone had the problem already and got an answer how to do this.

Thanks for Help,

Franzi


Solution

  • Bars are rendered by Androidplot's BarRenderer class which uses the Canvas.drawRect(...) method to draw individual bars. In order to get rounded edges it would either need to call Canvas.drawRoundRect or possibly even better, draw each bar as a path using Path.lineTo(...) and Path.arcTo(...) methods so that only the top of the bars are rounded. This functionality unfortunately does not exist yet but you could open a feature request if you want.

    Or you could implement it yourself by creating a custom renderer that extends BarRenderer and overriding drawBar(...). Documentation available here

    enter image description here