Reputation: 7266
I'm using MPAndroidChart and I want to archive something similar to the following chart:
Basically, I want to display labels (let's say all labels of one of the axis) inside bars in BarChart
or HorizontalBarChart
, in addition to the values of a bar itself.
The reason to do this is because, in my case, labels of YAxis are quite long, so it's not enough space to display them outside of the Chart. But inside each bar there is lots of space, guaranteed in my case. So it's quite reasonable to basically name each bar (what does this bar means) right inside it. I haven't found any API to do this (I was looking in v2.1.1).
I need this for HorizontalBarChart
, so labels would be also horisontal, but vertical labels for BarChart
would be also great!
Is there a way to do this? Any solutions would be helpful, including some custom additions to the library features.
Upvotes: 4
Views: 6626
Reputation: 51421
Well there is not really a feature to do this. However, there is a little hack (or at least I think there is) which you could try.
XAxis
to the left side and let the labels be drawn inside of the content area of the chart by calling chart.getXAxis().setPosition(XAxisPosition.BOTTOM_INSIDE)
In that way the labels should be drawn over the bars. You can further reposition the labels by using the setXOffset(...)
and setYOffset(...)
methods of the XAxis
class.
Upvotes: 5