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:
doesn't seems to have any impact. then I tried:
Does anyone had the problem already and got an answer how to do this. Thanks for Help, Franzi Here is a link to my original post:Â https://stackoverflow.com/questions/47310224/androidplot-xyplot-how-to-make-bars-with-rounded-corners |
Thanks for your hint. After long time I get to try your solution, but my problem now is now how can I replace the original Bar-Renderer inside the Plot with my own one?
public class RoundBarRenderer extends BarRenderer {
public RoundBarRenderer(XYPlot plot){
super(plot);
}
protected void drawBar(Canvas canvas, Bar bar, RectF rect) {
// null yVals are skipped:
if(bar.getY() == null) {
return;
}
BarFormatter formatter = getFormatter(bar.i, bar.series);
if(formatter == null) {
formatter = bar.formatter;
}
if(rect.height() > 0 && rect.width() > 0) {
if (formatter.hasFillPaint()) {
canvas.drawRect(rect.left, rect.top, rect.right, rect.bottom,
formatter.getFillPaint());
}
if (formatter.hasLinePaint()) {
//canvas.drawRect(rect.left, rect.top, rect.right, rect.bottom,
//formatter.getBorderPaint());
canvas.drawRoundRect(rect.left,rect.top,rect.right,rect.bottom,5,5,formatter.getBorderPaint());
}
}
PointLabelFormatter plf =
formatter.hasPointLabelFormatter() ? formatter.getPointLabelFormatter() : null;
PointLabeler pointLabeler =
formatter != null ? formatter.getPointLabeler() : null;
if (plf != null && plf.hasTextPaint() && pointLabeler != null) {
canvas.drawText(pointLabeler.getLabel(bar.series, bar.i),
rect.centerX() + plf.hOffset, bar.yPix + plf.vOffset,
plf.getTextPaint());
}
}
}
Thanks
Franzi
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(...)
.