2

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

Franz
  • 358
  • 6
  • 18

1 Answers1

1

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

Nick
  • 8,181
  • 4
  • 38
  • 63
  • I have tried your solution, but my problem now is, that I can't find any solution to replace the Standard BarRenderer-Object with the Custom one. Is there any known way to do this? Thanks for Answers, Franzi – Franz Dec 07 '17 at 12:38
  • Most likely you didnt create a custom Formatter to go along with your Renderer. The [BarPlotExample source](https://github.com/halfhp/androidplot/blob/master/demoapp/src/main/java/com/androidplot/demos/BarPlotExampleActivity.java) has a working example of how to define and use a custom Renderer – Nick Dec 07 '17 at 14:00
  • I've added a link to custom renderer documentation to my answer. – Nick Dec 08 '17 at 14:50
  • Thanks, that's what I needed. – Franz Dec 11 '17 at 11:36
  • Sorry for asking again but I get the following, when implementing your solution : ErrorError:(26, 20) error: name clash: drawBar(Canvas,Bar,RectF) in RoundedBarRenderer and drawBar(Canvas,Bar,RectF) in BarRenderer have the same erasure, yet neither overrides the other – Franz Dec 12 '17 at 13:31
  • Most likely you just need to update to anroidplot 1.5.2 – Nick Dec 12 '17 at 16:15