MPAndroidChart柱状图禁用右侧图例

20

我需要从 BarChart 中移除右侧的图例。

这是我的代码。

    mChart = (BarChart) rootView.findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);
    mChart.setDescription("");
    mChart.setMaxVisibleValueCount(60);
    mChart.setPinchZoom(false);
    mChart.setDrawGridBackground(false);
    mTf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Regular.ttf");

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTypeface(mTf);
    xAxis.setDrawGridLines(false);
    xAxis.setSpaceBetweenLabels(2);

    ValueFormatter custom = new MyValueFormatter();

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(mTf);
    leftAxis.setLabelCount(8);
    leftAxis.setValueFormatter(custom);
    leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setSpaceTop(15f);

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.BELOW_CHART_LEFT);
    l.setForm(LegendForm.SQUARE);
    l.setFormSize(9f);
    l.setTextSize(11f);
    l.setXEntrySpace(4f);

    mChart.animateXY(3000, 3000);

输入图像描述

谢谢!

3个回答

60

添加这行内容

rightAxis.setDrawLabels(false); 

隐藏仅标签

隐藏整个右轴,请调用:

rightAxis.setEnabled(false);

6
一个简单的一行代码:
chart.getAxisRight().setEnabled(false);

2

对于使用 Kotlin 语言的人:

chart.axisRight.isEnabled = false

希望我能帮助你!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接