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