Metehan Toksoy
Metehan Toksoy

Reputation: 1935

MPAndroidChart hide background grid

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

Upvotes: 55

Views: 43554

Answers (7)

Muhammed Haris
Muhammed Haris

Reputation: 380

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);

Upvotes: 0

user3985106
user3985106

Reputation:

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);

Upvotes: 13

Twinkle
Twinkle

Reputation: 47

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

chart.setDrawBorders(false);

Upvotes: 0

Shaon
Shaon

Reputation: 2724

Hide Background grid

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

Upvotes: 9

Zhangali Bidaibekov
Zhangali Bidaibekov

Reputation: 701

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)

Upvotes: 11

badarshahzad
badarshahzad

Reputation: 1297

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

Upvotes: 14

MightySeal
MightySeal

Reputation: 2315

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)

Upvotes: 135

Related Questions