如何隐藏MPAndroidChart中的图例和轴?

Gun*_*lan 50 android mpandroidchart

他们是否有可能隐藏这张照片中的所有圆形物品.

在此输入图像描述

我使用了以下代码,

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);
}
Run Code Online (Sandbox Code Playgroud)

更新

如何隐藏此图像中的圆角部分?

在此输入图像描述

cod*_*zjx 151

是的,可以,只需使用以下代码:

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

mChart.getLegend().setEnabled(false);   // Hide the legend 
Run Code Online (Sandbox Code Playgroud)


kit*_*ode 6

它似乎mChart.SetDescription()不再接受字符串。

该方法现在接受一个描述类的实例,如下所示: mChart.setDescription(Description description)

所以要修改或删除图表描述,你可以像下面那样做

Description description = new Description();
description.setText("");
mChart.setDescription(description);
Run Code Online (Sandbox Code Playgroud)


Ani*_*nil 5

以下代码适用于所有图表

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


Pra*_*abs 5

按照这个答案

mChart.getXAxis().setDrawLabels(false); 将隐藏整个X轴(此问题要求)。

为了定位X轴,可以使用以下代码。

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
Run Code Online (Sandbox Code Playgroud)

位置可以设置为

  • 底部
  • BOTH_SIDED
  • BOTTOM_INSIDE
  • 最佳
  • TOP_INSIDE

如果您只想隐藏特定的侧轴而不是隐藏整个轴,这将很有帮助。