Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 530
benoffi7 Avatar asked Apr 30 '15 14:04

benoffi7


2 Answers

Add this line

rightAxis.setDrawLabels(false); 

To hide only the labels.

For hiding the whole right axis, call:

rightAxis.setEnabled(false);
like image 91
benoffi7 Avatar answered Oct 06 '22 20:10

benoffi7


A simple one liner:

chart.getAxisRight().setEnabled(false);
like image 37
Chris Knight Avatar answered Oct 06 '22 19:10

Chris Knight