Reputation: 111
I used legend.setPosition(Legend.LegendPosition.RIGHT_OF_CHART_CENTER);
it works, but I want that the legend was at the top
if i use legend.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
the legend and the graph overlap
maybe there is a way to change the position of the chart?
Upvotes: 0
Views: 4651
Reputation: 969
Yes, you can when you changing the value of the offset:
pieChart.setExtraTopOffset(15);
pieChart.setExtraBottomOffset(15);
pieChart.setExtraLeftOffset(0);
pieChart.setExtraRightOffset(50);
Or with one line
setExtraOffsets(float left, float top, float right, float bottom)
result:
A good example with its parameters and with some description: https://www.programmersought.com/article/99524092993/
Upvotes: 1
Reputation: 146
try to Set all the data to chart after all customization and everything will work fine .. like this :
l.setCustom(arrayOf(firstLegend, secondLegend))
l.verticalAlignment = Legend.LegendVerticalAlignment.BOTTOM
l.horizontalAlignment = Legend.LegendHorizontalAlignment.LEFT
l.orientation = Legend.LegendOrientation.HORIZONTAL
l.setDrawInside(false)
and then set the data to chart ..
chart.data = data // set the data and list of labels into chart
Upvotes: 1
Reputation: 301
This method deprecated better to use this.
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
for reference you can check here The legend can't display when call setPosition(LegendPosition.BELOW_CHART_CENTER)
Upvotes: 2
Reputation: 111
I was able to get the desired result using
legend.setPosition(Legend.LegendPosition.ABOVE_CHART_LEFT);
legend.setWordWrapEnabled(true);
legend.setMaxSizePercent(0.20f);
Upvotes: 1
Reputation: 3189
Use below line:
legend.setPosition(Legend.LegendPosition.ABOVE_CHART_RIGHT);
Upvotes: 1