Skip to main content

Android : MPAndroidChart how to remove values on right side in chart?

I have the following chart which is displaying some values.

I would like to hide/ remove values on the right side, because on the left side are enough.

See image below:

enter image description here

And code is following:

public class MainActivity extends AppCompatActivity implements
        OnChartValueSelectedListener{
    private LineChart mDataLineChart;
    private RelativeLayout mRelativeLayout;

    private LineChart mChart;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_linechart);

        // Set chart
        setChart();
        // add data
        setData2(3, 155);
        // ANIMATE CHART
        animateChart();
    }


    private void setChart() {
        mChart = (LineChart) findViewById(R.id.chart1);
        mChart.setOnChartValueSelectedListener(this);

        ////////////////////////////////
        // SET DESCRIPTION COLOR
        ////////////////////////////////
        mChart.setDescriptionColor(getResources().getColor(R.color.chart_desc_color));
        ////////////////////////////////
        // BORDERS SURROUNDING THE CHART
        ////////////////////////////////
        mChart.setDrawBorders(true);
        mChart.setBorderColor(getResources().getColor(R.color.chart_border));
        mChart.setBorderWidth(2);
        ////////////////////////////////
        // CHART BG COLOR
        ////////////////////////////////
        mChart.setBackgroundColor(getResources().getColor(R.color.chart_bg));
        ////////////////////////////////
        // GRID BG COLOR
        ////////////////////////////////
        mChart.setDrawGridBackground(true);
        mChart.setGridBackgroundColor(getResources().getColor(R.color.chart_bg));

        ////////////////////////////////
        // OTHER SETTINGS
        ////////////////////////////////
        mChart.setDescription("");
        mChart.setNoDataTextDescription("You need to provide data for the chart.");
        // enable touch gestures
        mChart.setTouchEnabled(true);
        mChart.setDragDecelerationFrictionCoef(0.9f);
        // enable scaling and dragging
        mChart.setDragEnabled(true);
        mChart.setScaleEnabled(true);
        mChart.setHighlightPerDragEnabled(true);
        // if disabled, scaling can be done on x- and y-axis separately
        mChart.setPinchZoom(true);

    }


    private void setData2(int count, float range) {

        ////////////////////////////////
        // X axis values (labels)
        ////////////////////////////////
        ArrayList xVals = new ArrayList();
        for (int i = 0; i < count; i++) {
            xVals.add((i) + " day");
        }

        ////////////////////////////////
        // Y axis values (value in linechart)
        ////////////////////////////////
        ArrayList yVals1 = new ArrayList();
        for (int i = 0; i < count; i++) {
            float mult = range / 2f;
            float val = (float) (Math.random() * mult) + 50;// + (float)
            // ((mult *
            // 0.1) / 10);
            yVals1.add(new Entry(val, i));
        }

        ////////////////////////////////
        // SETTING FOR LINEAR LINE
        ////////////////////////////////
        LineDataSet set1 = new LineDataSet(yVals1, "Pressure mm/Hg");
        set1.setAxisDependency(AxisDependency.LEFT);
        set1.setLineWidth(2f);
        set1.setCircleSize(5f);
        set1.setColor(getResources().getColor(R.color.chart_line_color));
        set1.setCircleColor(getResources().getColor(R.color.chart_line_color));
        set1.setFillColor(getResources().getColor(R.color.chart_line_color));
        set1.setDrawCircleHole(true);

        ArrayList dataSets = new ArrayList();
        dataSets.add(set1); // add the datasets

        ////////////////////////////////
        // SETTING FOR DATASET (FONT SIZE, )
        ////////////////////////////////
        LineData data = new LineData(xVals, dataSets);
        data.setValueTextColor(Color.BLACK);
        data.setValueTextSize(9f);

        ////////////////////////////////
        // SET WHOLE DATASET TO CHART
        ////////////////////////////////
        mChart.setData(data);
    }

    private void animateChart() {
        ////////////////////////////////
        // ANIMATION DURATION
        ////////////////////////////////
        mChart.animateX(1000);
        ////////////////////////////////
        // SET LEGEND BOTTOM DATA TEXT
        ////////////////////////////////
        XAxis xAxis = mChart.getXAxis();
        xAxis.setTextSize(12f);
        xAxis.setTextColor(Color.BLACK);
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setSpaceBetweenLabels(1);



    }

    @Override
    public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
        Log.i("Entry selected", e.toString());
    }

    @Override
    public void onNothingSelected() {
        Log.i("Nothing selected", "Nothing selected.");
    }

}

I tried to search in documentation on Github:

https://github.com/PhilJay/MPAndroidChart/wiki/The-Axis

But without luck.

How can i remove values from right please?

Many thanks for any advice.

Solved

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

put this code on your setChart();


You may want to check example application and corresponding codes. The application includes 2 related examples: Line Chart and Line Chart (Dual YAxis). The first is what you want and the latter is what you have right know.

App link: https://play.google.com/store/apps/details?id=com.xxmassdeveloper.mpchartexample

Code: https://github.com/PhilJay/MPAndroidChart/tree/master/MPChartExample


Comments

Popular posts from this blog

C# How to spawn Enemies and move them? [closed]

I am trying to spawn enemies and move them from left to right with a timer how can i do this? Example: int count; timer (every 1 sec) { Enemy somename+count = new Enemy(); count++; } timer (every 0.001 sec) { somename+count.x++; } Solved Your fundamental problem seems to be lacking a way to store references to all of your enemies. Generics and collections provide a solution to this type of problem. I'll use a List , which is the most basic such collection. There are many others, however, that each have their own useful properties. Consider : private class Enemy { public int position; } private List enemyList = new List (); private void timer1_Tick(object sender, EventArgs e) { enemyList.Add(new Enemy()); } private void timer2_Tick(object sender, EventArgs e) { foreach(Enemy enemy in enemyList) { enemy.position++; } } Also consider that updating a large list of visual objects every 0.001 second is useless and wast...

Can't seem to get my method (in Java) to compile correctly

I am trying to figure out exactly what is wrong with my winorTie method in this little tictacttoe game I am trying to create. Would anyone be able to help? Thanks package tictactoegame; /** * * @author Douglas Boulden */ public class tictactoegame { static int [][] gameboard; static final int EMPTY = 0; static final int NOUGHT = -1; static final int CROSS = 1; static void set (int val, int row) throws IllegalArgumentException { int col = 0; if (gameboard[row][col] == EMPTY) gameboard[row][col] = val; else throw new IllegalArgumentException("Player already there!"); } static void displayBoard () { for (int[] gameboard1 : gameboard) { System.out.print("|"); for (int c = 0; c Solved Some of this was mentioned in the comments, but these conditions fundamentally don't make sense: if (gameboard [0][0] == NOUGHT && gameboard [0][...