51

I'm using MPAndroidChart - LineChart in my android application. I want to remove gridlines from the background . How can I remove gridlines from the background?

MPAndroidChart Line Chart Example

Library: MPAndroidChart on GitHub

EDIT: I created my own custom LineChart using this library. I want to remove bottom line. how can I do that too? Custom LineChart

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
Metehan Toksoy
  • 1,885
  • 3
  • 22
  • 39

7 Answers7

133

Use this:

mChart.getAxisLeft().setDrawGridLines(false);
mChart.getXAxis().setDrawGridLines(false);

Please note you may need right axis or both of them. It depends on axis you are actually using.

UPDATE: Is it axis line? If it is, then simply chart.getXAxis().setEnabled(false)

Also possible: chart.getAxisLeft().setDrawAxisLine(false)

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
MightySeal
  • 2,293
  • 2
  • 17
  • 32
14

Simply below three lines remove horizontal and vertical lines in the bar chart. enter image description here

barChart.getAxisRight().setDrawGridLines(false);
barChart.getAxisLeft().setDrawGridLines(false);
barChart.getXAxis().setDrawGridLines(false);

enter image description here

badarshahzad
  • 1,227
  • 16
  • 25
11

Non of the above helped me to hide all axis lines. I just needed clean sheet with bars. Code below did the work:

    barChart.xAxis.isEnabled = false
    barChart.axisLeft.isEnabled = false
    barChart.axisRight.isEnabled = false

provided in kotlin, in java methods will look like that: setEnabled(false)

Zhangali Bidaibekov
  • 591
  • 1
  • 7
  • 13
10

Use this code to clear all lines with labels:

mChart.setTouchEnabled(true);
mChart.setClickable(false);
mChart.setDoubleTapToZoomEnabled(false);
mChart.setDoubleTapToZoomEnabled(false);

mChart.setDrawBorders(false);
mChart.setDrawGridBackground(false);

mChart.getDescription().setEnabled(false);
mChart.getLegend().setEnabled(false);

mChart.getAxisLeft().setDrawGridLines(false);
mChart.getAxisLeft().setDrawLabels(false);
mChart.getAxisLeft().setDrawAxisLine(false);

mChart.getXAxis().setDrawGridLines(false);
mChart.getXAxis().setDrawLabels(false);
mChart.getXAxis().setDrawAxisLine(false);

mChart.getAxisRight().setDrawGridLines(false);
mChart.getAxisRight().setDrawLabels(false);
mChart.getAxisRight().setDrawAxisLine(false);

and use this to remove value of all points:

LineDataSet set1;
set1.setDrawValues(false);
Nader MA
  • 117
  • 1
  • 5
9

Hide Background grid

    chart.getXAxis().setDrawGridLines(false);
    chart.getAxisLeft().setDrawGridLines(false);
    chart.getAxisRight().setDrawGridLines(false);
Shaon
  • 2,496
  • 26
  • 27
0

to remove borders from chart you can use setDrawBorder(boolean) property.

chart.setDrawBorders(false);

Twinkle
  • 37
  • 11
0

code for removing outer line:

barChart.getAxisRight().setDrawAxisLine(false); 

barChart.getAxisLeft().setDrawAxisLine(false); 

barChart.getXAxis().setDrawAxisLine(false);

code for removing gridline

barChart.getAxisRight().setDrawGridLines(false);

barChart.getAxisLeft().setDrawGridLines(false);

barChart.getXAxis().setDrawGridLines(false);
Muhammed Haris
  • 340
  • 1
  • 5
  • 15