Mpandroidchart: Grid Lines are always shown regardless of setDrawGridLines() call.

Created on 8 Jun 2016  路  6Comments  路  Source: PhilJay/MPAndroidChart

Using BarChart, when the method call BarChart.setDrawGridLines(false) is made it still shows grid background. By my understanding calling this method is enough to disable gridlines. Other things work fine on updating the chart. Using following code.

    barChart.setData(barData);
    barChart.setDrawGridBackground(false);
    barChart.notifyDataSetChanged();   
    barChart.invalidate();

_EDIT:_ I have managed to remove vertical grid lines by calling
barChart.getXAxis().setDrawGridLines(false),
however, horizontal lines are there and there is no method for getYAxis(), is this possible?

Most helpful comment

@Nfear, depending on which axis is enabled and has the grid lines, you can disable it with the code below. binding.chart.setDrawGridBackground(false); disables the grid background and not the grid lines.

binding.chart.getXAxis().setDrawGridLines(false); // disable grid lines for the XAxis
binding.chart.getAxisLeft().setDrawGridLines(false); // disable grid lines for the left YAxis
binding.chart.getAxisRight().setDrawGridLines(false); // disable grid lines for the right YAxis

All 6 comments

@talhahasanzia Maybe chart.getAxisLeft( ) and chart.getAxisRight( ) might be of help?

@TR4Android has the solution.

So what does setDrawGridBackground(false) exactly do if it doesn't disable the grid? I don't notice any changes.

@Nfear Some code would be helpful. Do you call invalidate() on your chart after disabling the grid?

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="2">

    <com.github.mikephil.charting.charts.BarChart
        android:id="@+id/chart"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

</LinearLayout>

I use Data Binding Library to access the chart and it is shown on a support.v4.app.Fragment.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    binding.chart.setDrawGridBackground(false);
    binding.chart.invalidate();
}

The chart is showing, but the grid is still drawn. If I use the solution provided by you earlier it works, but that doesn't answer the question of why setDrawGridBackground(false); doesn't.

@Nfear, depending on which axis is enabled and has the grid lines, you can disable it with the code below. binding.chart.setDrawGridBackground(false); disables the grid background and not the grid lines.

binding.chart.getXAxis().setDrawGridLines(false); // disable grid lines for the XAxis
binding.chart.getAxisLeft().setDrawGridLines(false); // disable grid lines for the left YAxis
binding.chart.getAxisRight().setDrawGridLines(false); // disable grid lines for the right YAxis
Was this page helpful?
0 / 5 - 0 ratings

Related issues

madroidmaq picture madroidmaq  路  27Comments

arunrajput1007 picture arunrajput1007  路  15Comments

pankaj210891 picture pankaj210891  路  15Comments

onyame picture onyame  路  116Comments

patelanil2007 picture patelanil2007  路  26Comments