14

I'm using the MPAndroidChart for my bar graph and I'm struggling with removing the padding of the graph (see pic below)

enter image description here

My approaches regarding this problem were:

  1. chart.setDrawLegend(false);
    chart.setDrawMarkerViews(false);
    chart.setDrawUnitsInChart(false);
    chart.setDrawValueAboveBar(false);
    chart.setDrawXLabels(false);
    chart.setDrawYLabels(false);
    chart.setDescription("");
    
  2. chart.setOffsets(0, 0, 0, 0);
    chart.getTransformer().prepareMatrixValuePx(chart);
    chart.getTransformer().prepareMatrixOffset(chart);
    chart.getContentRect().set(0, 0, chart.getWidth(),chart.getHeight());
    

And nothing has worked so far. Do you know another approach for this problem?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Asilvia
  • 271
  • 1
  • 3
  • 9

3 Answers3

14

I know that's pretty late for answer, but now Chart has the following method:

setViewPortOffsets(-40f, 0f, 0f, 0f)

(setting weird -40f value instead 0 seems unnatural, but it still works)

Danil
  • 141
  • 1
  • 4
2

I am currently working on an update that will allow to set all paddings!

The currently available method for setting the offsets is buggy.

In the meantime you could try to set a negative padding or margin via .xml. Let me know if this works!

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
  • 1
    Negative margin does only work for left and right, but not for bottom margins. I tested it for LineCharts in a CardView. – Strassenrenner May 28 '15 at 09:08
  • 1
    @Strassenrenner I set all of them to negative and it worked – suku Nov 18 '16 at 06:21
  • @Philip Jahoda I am using combined chart and want to set offset on x axis but its not working even tried setting negative margin. – Saurabh Dec 15 '16 at 19:18
0

This worked for me:

barChart.getAxisLeft().setXOffset(-9f);
Nishant Soni
  • 658
  • 1
  • 9
  • 19