如何在MPAndroidChart中隐藏图例和坐标轴?

问题描述:

他们是否有可能隐藏此图片中的所有圆角项目。如何在MPAndroidChart中隐藏图例和坐标轴?

enter image description here

我用下面的代码,

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

更新

如何隐藏拱形部分从该图像?

enter image description here

+0

哪里是你的'MPAndroidChart'码? – Raptor 2015-03-13 11:18:07

+0

@Raptor我已更新。 – Gunaseelan 2015-03-13 11:19:59

+0

嘿@Gunaseelan,你可以看看这个http://stackoverflow.com/questions/38975333/mpandroidchart-horizo​​ntalbarchart-customize-label?noredirect=1#comment65304760_38975333 – Cloy 2016-08-16 13:14:00

是的,是可能的,只是用下面的代码:

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

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

我的MPAndroidChart版本是v2.0.7 – codezjx 2015-03-13 11:52:24

+0

可以隐藏'类别1,类别2,类别3'的传奇兄弟。 – Gunaseelan 2015-03-13 12:05:45

+0

在我的项目中,我使用mChart.getXAxis()。setDrawLabels(false)来隐藏它。但是我的x轴是左边的,不是正确的。 – codezjx 2015-03-13 12:13:08

下面的代码适用于饼图。尝试为图表获取相同的方法。

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

对不起,这一个没有工作。 – Gunaseelan 2015-03-13 11:40:35

+0

@Gunaseelan没有可用的方法horizo​​ntalBarChart.getLegend()? – Pooja 2015-03-13 11:41:30

+0

不,'Legend.LegendPosition.NONE'不可用。 – Gunaseelan 2015-03-13 11:45:33

下面的代码工作,为所有图表

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

作为每this answer

mChart.getXAxis().setDrawLabels(false);将隐藏整个X轴(根据需要为这个问题)。

对于定位X轴,下面的代码工作。

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

位置可以设置为

  • BOTTOM
  • BOTH_SIDED
  • BOTTOM_INSIDE
  • TOP
  • TOP_INSIDE

这可以帮助你试图只隐藏特定的侧轴而不是隐藏整个轴。

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

看来mChart.SetDescription()不再接受字符串。

的方法现在接受这样的描述类的一个实例: mChart.setDescription(Description description)

所以,修改或删除图表说明你可能不喜欢它下面

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