In MPAndroidChart library I have combined chart which consist of 1 Line data and 1 Bar data. I have 2 buttons lets say on
- Button 1 click Bar Data should be shown and Line Data should Hide.
- Button 2 click Line Data should be shown and Bar Data should Hide.
Initially I have loaded the Bar Chart same I have done on Button 1 Click event. What I am doing at the moment is
on Button 1 Click I do fllowing :
CombinedData data = new CombinedData(getXAxisValues()); data.setData(generateBarData()); mChart.setData(data); mChart.invalidate();on Button 2 Click:
mChart.getData().removeDataSet(mChart.getData().getDataSetByIndex(0)); mChart.getData().notifyDataChanged(); mChart.notifyDataSetChanged() CombinedData data = new CombinedData(getXAxisValues()); data.setData(generateLineData()); mChart.setData(data); mChart.invalidate();
On Button 2 click it gives me following exception
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.github.mikephil.charting.data.LineData.notifyDataChanged()' on a null object reference
I am new with Android programming. Kindly help me in this matter. Thanks in Advance.