Mpandroidchart: How to show only left Y axis and down x axis in bar chart

Created on 26 Oct 2016  路  13Comments  路  Source: PhilJay/MPAndroidChart

How to show only left Y axis and down x axis in bar chart ie how to remove the the grid lines with right y axis and top x axis.

Want to see like this : Whats the code ?
chart

Most helpful comment

To disable the right yAxis

    YAxis rightYAxis = barChart.getAxisRight();
    rightYAxis.setEnabled(false);

You may want to use similar example for xAxis.

All 13 comments

Look at axis styling. Especially at setDrawGridLines and setPosition.

Can any one send me the sample code for this

There is a example at the bottom of the page.

To disable the right yAxis

    YAxis rightYAxis = barChart.getAxisRight();
    rightYAxis.setEnabled(false);

You may want to use similar example for xAxis.

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle b) {

    view = inflater.inflate(R.layout.bar_chart_fragment, container, false);

    final BarChart chart = (BarChart) view.findViewById(R.id.bar_chart);

    BarData data = new BarData(getXAxisValues(), getDataSet());
    chart.setData(data);
    chart.setDrawValueAboveBar(false);
    chart.getXAxis().setTextSize(15f);
    chart.setDescription("Percent(%)");
    //chart.getLegend().setEnabled(false);

    // Hide the desc value of each bar on top
    chart.getXAxis().setEnabled(false);

    YAxis rightYAxis = chart.getAxisRight();
    rightYAxis.setEnabled(false);

    chart.animateXY(2000, 2000);
    chart.invalidate();

        @Override
        public void onNothingSelected() {

        }
    });

    return view;
}

private ArrayList<BarDataSet> getDataSet() {
    ArrayList<BarDataSet> dataSets = null;

    ArrayList<BarEntry> valueSet1 = new ArrayList<>();
    BarEntry v1e1 = new BarEntry(96.000f, 0); // Jan
    valueSet1.add(v1e1);
    BarEntry v1e2 = new BarEntry(82.000f, 1); // Feb
    valueSet1.add(v1e2);
    BarEntry v1e3 = new BarEntry(88.000f, 2); // Mar
    valueSet1.add(v1e3);
    BarEntry v1e4 = new BarEntry(52.000f, 3); // Apr
    valueSet1.add(v1e4);

    BarDataSet barDataSet1 = new BarDataSet(valueSet1, "Availability of Drugs/Supplies");
    //Chnaging the color
    barDataSet1.setColor(Color.rgb(0, 169, 157));
    barDataSet1.setBarSpacePercent(30f);

    // Hide the value on each bar
    /*barDataSet1.setDrawValues(false);*/

    dataSets = new ArrayList<>();
    dataSets.add(barDataSet1);
    return dataSets;
}

private ArrayList<String> getXAxisValues() {
    ArrayList<String> yAxis = new ArrayList<>();
    yAxis.add("Well behaved staff (Total)");
    yAxis.add("Utilization of untied fund adequate (Total)");
    yAxis.add("Awareness generation (use ofIEC/BCC) (Total)");
    yAxis.add("Grievance redressal mechanismin place (Total)");

    return yAxis;
}

++++++++++++++++++++++++++++++++++++
After this i found the design like this, but i want to remove the x axis also
+++++++++++++++++++++++++++++++++++++

screenshot_2016-10-28-15-53-22

To show xAxis on bottom, please use

 chart.getXAxix()..setPosition(XAxis.XAxisPosition.BOTTOM);

in place of

chart.getXAxis().setEnabled(false);

after putting
chart.getXAxix()..setPosition(XAxis.XAxisPosition.BOTTOM);

instaed of

chart.getXAxis().setEnabled(false);

I am getting the result like this : kindly help me sir i want to remove all lines except left Y axis and botton X axis.

screenshot_2016-10-28-18-35-25

To disable the grid lines, you have to use

chart.getXAxis().setDrawGridLines(false);

YAxis rightYAxis = barChart.getAxisRight();
rightYAxis.setEnabled(false);
rightYAxis.setDrawGridLines(false);

Please look into the wiki for more information...

How to remove the x axis grid lines except the button x axis line

screenshot_2016-11-02-12-52-06

When i am trying this :

final BarChart chart = (BarChart) view.findViewById(R.id.bar_chart);

    BarData data = new BarData(getXAxisValues(), getDataSet());
    chart.setData(data);
    chart.setDrawValueAboveBar(false);
    chart.getXAxis().setTextSize(15f);
    chart.setDescription("Percent(%)");
    chart.getLegend().setEnabled(false);
    // Remove the grid line from background
    chart.getAxisLeft().setDrawGridLines(false);
    chart.getXAxis().setDrawGridLines(false);

    YAxis yAxis = chart.getAxisLeft();
    yAxis.setDrawGridLines(false);  

    // Disable the right y axis
    YAxis rightYAxis = chart.getAxisRight();
    rightYAxis.setEnabled(false);
    rightYAxis.setDrawGridLines(false);

    // Hide the desc value of each bar on top
    chart.getXAxis().setEnabled(false);

    chart.animateXY(2000, 2000);
    chart.invalidate();
    chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
        @Override
        public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
            if (e != null) {
                String name = chart.getData().getXVals().get(e.getXIndex());
                Float value = e.getVal();
                showMsg(name,value);
            }
        }

        @Override
        public void onNothingSelected() {

        }
    });

my chart is like this, it remove all grid with button x axis also, so how to do this ,i want only the left y axis with button x axis.

screenshot_2016-11-03-11-09-02

Try this

        XAxis xAxis = chart.getXAxis();
        xAxis.setEnabled(true);
        xAxis.setDrawGridLines(false);
        xAxis.setTextSize(15f);
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

i am using horizontal bar graph i want to set max value in y in single horizontal bar graph
please help

Closing for inactivity

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chathudan picture chathudan  路  3Comments

SutharRohit picture SutharRohit  路  3Comments

AiTheAnswer picture AiTheAnswer  路  3Comments

blotfi picture blotfi  路  3Comments

rohitkumarbhagat picture rohitkumarbhagat  路  3Comments