slodeveloper
slodeveloper

Reputation: 238

Too much space between graph and legend also x labels get cut off

The names of x labels are too long to be displayed as they are, so i desided to rotate them by -45 degree xAxis.setLabelRotationAngle(-45);.

The end result is shown in the picture below. As you can see the last x label gets cut off... Also there is too much space between graph and legend.

Relavant part of code:

BarData data = new BarData(arBdataSet);
data.setValueTextSize(12f);

float groupSpace = 0.02f;
float barSpace = 0.01f;
float barWidth=(1-groupSpace-(barSpace*intemInGroups))/intemInGroups;

data.setBarWidth(barWidth);
Legend leg=barChart.getLegend();
leg.setEnabled(true);
leg.setCustom(lear);
leg.setWordWrapEnabled(true);

barChart.setVisibility(View.VISIBLE);
barChart.setData(data);

YAxis leftAxis = barChart.getAxisLeft();
leftAxis.setValueFormatter(new MyGraphValFormatter(getResources()));
leftAxis.setSpaceTop(1f);
leftAxis.setAxisMinimum(0f);

XAxis xaPc=barChart.getXAxis();
xaPc.setLabelRotationAngle(-45);
xaPc.setPosition(XAxis.XAxisPosition.TOP);
xaPc.setGranularity(1f);

xaPc.setValueFormatter(new IAxisValueFormatter() {

   @Override
   public String getFormattedValue(float value, AxisBase axis) {
       int val=opeHel.adjustNumberToFitArrayList((int)value,xLabelNames);
       return xLabelNames.get(val);
   }

});

xaPc.setCenterAxisLabels(true);

barChart.getXAxis().setAxisMinimum(0);
barChart.getXAxis().setAxisMaximum(0 + barChart.getBarData().getGroupWidth(groupSpace, barSpace) * xLabelNames.size());
barChart.groupBars(0, groupSpace, barSpace);
barChart.getDescription().setEnabled(false);

barChart.setFitBars(true);
barChart.invalidate();

Extra space between graph and legend

Questions:

Upvotes: 2

Views: 1773

Answers (1)

vihkat
vihkat

Reputation: 1035

I think it's automatically added offset because you rotated the labels. Maybe it's fixed in new versions. If not then use it:

setExtraOffsets(0f, 0f, 0f, 0f)

Upvotes: 3

Related Questions