benoffi7
benoffi7

Reputation: 3106

MPAndroidChart BarChart disable right legends

I need to remove right legends from BarChart.

This is my code.

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

enter image description here

Thanks!

Upvotes: 20

Views: 9353

Answers (3)

Geraldo Neto
Geraldo Neto

Reputation: 4040

For those using Kotlin lang:

chart.axisRight.isEnabled = false

Hope it helps!

Upvotes: 2

Chris Knight
Chris Knight

Reputation: 25074

A simple one liner:

chart.getAxisRight().setEnabled(false);

Upvotes: 6

benoffi7
benoffi7

Reputation: 3106

Add this line

rightAxis.setDrawLabels(false); 

To hide only the labels.

For hiding the whole right axis, call:

rightAxis.setEnabled(false);

Upvotes: 60

Related Questions