How to hide legends and axis in MPAndroidChart?

那年仲夏 提交于 2019-11-28 19:06:05
codezjx

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 
Prabs

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.

Following code work for all chart

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

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);

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

Legend l = mChart.getLegend();
l.setPosition(LegendPosition.NONE);
chart=(LineChart) findViewById(R.id.Chart);
chart.getLegend().setEnabled(false); // for hiding square on below graph
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!