How to hide legends and axis in MPAndroidChart?

AndroidMpandroidchart

Android Problem Overview


Is their any possibility to hide all rounded items from this picture.

enter image description here

I have used the following code,

public void setDataList(List<HorizontalBarChartData> dataList, Resources resources) {

    ArrayList<String> categories = new ArrayList<String>();
    ArrayList<BarEntry> values = new ArrayList<BarEntry>();
    ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
    BarDataSet set1;
    for (int i = 0; i < dataList.size(); i++) {
        categories.add(dataList.get(i).getName());
        values.add(new BarEntry(dataList.get(i).getValue(), i));
    }

    /*set1 = new BarDataSet(values, "Income, Expense, Disposable Income");*/
    set1 = new BarDataSet(values, "Category 1, Category 2, Category 3");
    set1.setBarSpacePercent(35f);
    set1.setColors(new int[]{resources.getColor(R.color.cyan_blue), resources.getColor(R.color.vermilion_tint), resources.getColor(R.color.sea_green)});
    dataSets.add(set1);

    BarData data = new BarData(categories, dataSets);
    data.setValueTextSize(10f);

    horizontalBarChart.setData(data);
}

Update

How to hide rounded part from this image?

enter image description here

Android Solutions


Solution 1 - Android

Yes, is possible, just using following code:

mChart.setDescription("");    // Hide the description
mChart.getAxisLeft().setDrawLabels(false);
mChart.getAxisRight().setDrawLabels(false);
mChart.getXAxis().setDrawLabels(false);

mChart.getLegend().setEnabled(false);   // Hide the legend 

Solution 2 - Android

As per this answer

mChart.getXAxis().setDrawLabels(false); will hide the entire X-Axis(as required for this question).

For positioning the X-Axis, following code works.

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

Position can be set to

  • BOTTOM
  • BOTH_SIDED
  • BOTTOM_INSIDE
  • TOP
  • TOP_INSIDE

This helps if you are trying to hide only the particular side axis instead of hiding the entire axis.

Solution 3 - Android

It appears mChart.setDescription() no longer accepts a String.

The method now accepts an instance of the Description Class like this: mChart.setDescription(Description description)

So to modify or delete the Chart Description you may do it like below

Description description = new Description();
description.setText("");
mChart.setDescription(description);

Solution 4 - Android

Following code work for all chart

Legend l = mchart.getLegend(); l.setEnabled(false);.

Solution 5 - Android

To hide description, use this

mChart.getDescription().setEnabled(false)

Solution 6 - Android

Below code works for PieChart. Try to get same method for your Chart.

Legend l = mChart.getLegend();
l.setPosition(LegendPosition.NONE);
        

Solution 7 - Android

chart=(LineChart) findViewById(R.id.Chart);
chart.getLegend().setEnabled(false); // for hiding square on below graph

Solution 8 - Android

Kotlin solution for MPAndroidChart:v3.1.0

chart.description.isEnabled = false // hide the description
chart.legend.isEnabled = false // hide the legend 

chart.xAxis.setDrawLabels(false) // hide bottom label
chart.axisLeft.setDrawLabels(false) // hide left label
chart.axisRight.setDrawLabels(false) // hide right label

Solution 9 - Android

I had the problem, that the bottom xAxis Labels are cutted off when I used mChart.getLegend().setEnabled(false)

Now I use chart.getLegend().setForm(Legend.LegendForm.NONE); instead and the labels are not cutted of anymore

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGunaseelanView Question on Stackoverflow
Solution 1 - AndroidcodezjxView Answer on Stackoverflow
Solution 2 - AndroidPrabsView Answer on Stackoverflow
Solution 3 - Androidkite_n_codeView Answer on Stackoverflow
Solution 4 - AndroidAnilView Answer on Stackoverflow
Solution 5 - AndroidJiyehView Answer on Stackoverflow
Solution 6 - AndroidPoojaView Answer on Stackoverflow
Solution 7 - Androidsaigopi.meView Answer on Stackoverflow
Solution 8 - AndroidLinhView Answer on Stackoverflow
Solution 9 - AndroidFalke DesignView Answer on Stackoverflow