MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

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

Open talhahasanzia opened this issue 10 years ago • 6 comments

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?

talhahasanzia avatar Jun 08 '16 04:06 talhahasanzia

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

taltstidl avatar Jun 08 '16 07:06 taltstidl

@TR4Android has the solution.

PhilJay avatar Jun 15 '16 11:06 PhilJay

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

sarendshorst avatar Nov 22 '16 16:11 sarendshorst

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

taltstidl avatar Nov 22 '16 16:11 taltstidl

<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.

sarendshorst avatar Nov 23 '16 09:11 sarendshorst

@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

ifeomaro avatar Nov 23 '16 16:11 ifeomaro