Mpandroidchart: Hiding everything except line chart (labels, numbers, borders, etc.)

Created on 20 Aug 2015  路  5Comments  路  Source: PhilJay/MPAndroidChart

Is it possible to hide everything except the line chart itself to achieve something like that:

line-chart

There are some methods to limit visible X and Y values and labels but I couldn't go further.

Most helpful comment

Calling all of these, you are left with only the line chart

     // Draw chart
    LineChart chart = (LineChart) findViewById(...); // fill in your chart

    // Prepare data
    ArrayList<Entry> values = new ArrayList<>();
    values.add(...)

    LineDataSet dataSet = new LineDataSet(values, "Label");

    dataSet.setDrawValues(false);
    dataSet.setLineWidth(2f);
    dataSet.setDrawCubic(true);

    dataSet.setDrawCircles(false);

    ArrayList<LineDataSet> dataSets = new ArrayList<>();
    dataSets.add(dataSet);

    ArrayList<String> xValues = new ArrayList<>();
    xValues.add(...);

    LineData data = new LineData(xValues, dataSets);

    chart.setData(data);

    // style chart
    chart.setBackgroundColor(getResources().getColor(...)); // use your bg color
    chart.setDescription(" ");
    chart.setDrawGridBackground(false);
    chart.setDrawBorders(false);

    chart.setAutoScaleMinMaxEnabled(true);

    // remove axis
    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setEnabled(false);
    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setEnabled(false);

    XAxis xAxis = chart.getXAxis();
    xAxis.setEnabled(false);

    // hide legend
    Legend legend = chart.getLegend();
    legend.setEnabled(false);

    chart.invalidate();

All 5 comments

Calling all of these, you are left with only the line chart

     // Draw chart
    LineChart chart = (LineChart) findViewById(...); // fill in your chart

    // Prepare data
    ArrayList<Entry> values = new ArrayList<>();
    values.add(...)

    LineDataSet dataSet = new LineDataSet(values, "Label");

    dataSet.setDrawValues(false);
    dataSet.setLineWidth(2f);
    dataSet.setDrawCubic(true);

    dataSet.setDrawCircles(false);

    ArrayList<LineDataSet> dataSets = new ArrayList<>();
    dataSets.add(dataSet);

    ArrayList<String> xValues = new ArrayList<>();
    xValues.add(...);

    LineData data = new LineData(xValues, dataSets);

    chart.setData(data);

    // style chart
    chart.setBackgroundColor(getResources().getColor(...)); // use your bg color
    chart.setDescription(" ");
    chart.setDrawGridBackground(false);
    chart.setDrawBorders(false);

    chart.setAutoScaleMinMaxEnabled(true);

    // remove axis
    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setEnabled(false);
    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setEnabled(false);

    XAxis xAxis = chart.getXAxis();
    xAxis.setEnabled(false);

    // hide legend
    Legend legend = chart.getLegend();
    legend.setEnabled(false);

    chart.invalidate();

With the latest build, to get this effect, you would have to use these settings:

        mChart.getAxisLeft().setDrawLabels(false);
        mChart.getAxisRight().setDrawLabels(false);
        mChart.getXAxis().setDrawLabels(false);
      // https://stackoverflow.com/questions/31263097/mpandroidchart-hide-background-grid
        mChart.getAxisLeft().setDrawGridLines(false);
        mChart.getXAxis().setDrawGridLines(false);
        mChart.getAxisRight().setDrawGridLines(false);

        XAxis xAxis = mChart.getXAxis();
        xAxis.setEnabled(false);

        YAxis yAxis = mChart.getAxisLeft();
        yAxis.setEnabled(false);

        YAxis yAxis2 = mChart.getAxisRight();
        yAxis2.setEnabled(false);

        mChart.setDrawBorders(false);
        mChart.setDrawGridBackground(false);

        mChart.getLegend().setEnabled(false);
        // no description text
        mChart.getDescription().setEnabled(false);

        // enable touch gestures
        mChart.setTouchEnabled(true);

        // enable scaling and dragging
        mChart.setDragEnabled(false);
        mChart.setScaleEnabled(false);
        // mChart.setScaleXEnabled(true);
        // mChart.setScaleYEnabled(true);

        // if disabled, scaling can be done on x- and y-axis separately
        mChart.setPinchZoom(false);
        mChart.setAutoScaleMinMaxEnabled(true);
        // hide legend
        Legend legend = mChart.getLegend();
        legend.setEnabled(false);

You saved my weekend! thanks!

It works like charm! Thanks!

how to hide the axis (Y,X) when clicking on the chart?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andreyfel picture andreyfel  路  3Comments

mrZizik picture mrZizik  路  3Comments

AiTheAnswer picture AiTheAnswer  路  3Comments

vishvendu picture vishvendu  路  3Comments

manucheri picture manucheri  路  3Comments