2

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:

  • How can i remove that extra space between graph and legend (i want to achieve that graph takes as much space as possible and of course, legend has to be visible...) ?
  • How can i prevent that last x label will not be cut off (of course without removing it) ?
0

1 Answer 1

3

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.