2

I want to remove the description in MPAndroidChart. I don't know where the description comes from, here is a pic
enter image description here

And here is what I want to,I think there should have two labels, I set it by:

LineDataSet lineDataSet = new LineDataSet(y1,"dataSet1");

enter image description here

here is my code

public class MainActivity extends AppCompatActivity {

    LineChart lineChart;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lineChart=(LineChart)findViewById(R.id.main_chart);
        ArrayList<String> xAXES = new ArrayList<>();
        ArrayList<Entry> y1=new ArrayList<>();
        ArrayList<Entry> y2 =new ArrayList<>();
        double x=0;
        int numdatapoint=10;
        for (int i = 0; i <numdatapoint ; i++) {
            float sinfunction = i;
            float confunction =i+2;
            x=x+0.1;
            y1.add(new Entry(sinfunction,i-1));
            y2.add(new Entry(confunction,i+2));
            xAXES.add(i,String.valueOf(i));
        }
        String [] xaxes =new String [xAXES.size()];
        for (int i = 0; i <xAXES.size() ; i++) {
            xaxes[i]=xAXES.get(i).toString();
        }
        ArrayList<ILineDataSet> lineDataSets = new ArrayList<>();
        LineDataSet lineDataSet = new LineDataSet(y1,"dataSet1");
        lineDataSet.setColor(Color.BLUE);
        LineDataSet lineDataSetY = new LineDataSet(y2,"dataset2");
        lineDataSet.setColor(Color.RED);
        lineDataSets.add(lineDataSet);
        lineDataSets.add(lineDataSetY);
        LineData line =new LineData();
        lineChart.setData(new LineData(lineDataSets));
        lineChart.setVisibleXRangeMaximum(10f);
       }
    }
Cœur
  • 37,241
  • 25
  • 195
  • 267
R Probaby
  • 45
  • 5

3 Answers3

1

It looks like you may have set the position of the X-Axis to the top?

You can change this by using the setPosition(XAxisPosition pos); function (Sets the position where the XAxis should appear. Choose between TOP, BOTTOM, BOTH_SIDED, TOP_INSIDE or BOTTOM_INSIDE.)

Reference: https://github.com/PhilJay/MPAndroidChart/wiki/XAxis

Edit: Looks like you're after the Legend? https://github.com/PhilJay/MPAndroidChart/wiki/Legend

Isaac
  • 1,442
  • 17
  • 26
  • its not ,i just want to have two label,the bottom should have two label,set by LineDataSet lineDataSet = new LineDataSet(y1,"son");,but its disappear – R Probaby Sep 06 '16 at 05:50
  • i have set lineChart.getLegend().setEnabled(true); but its still not change,and legend not appear – R Probaby Sep 06 '16 at 06:50
0

Here is your above code with correction and running perfectly you can find and run in your project.

public class MainActivity extends AppCompatActivity 
{ 
    LineChart lineChart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainchart);
        lineChart=(LineChart)findViewById(R.id.line_chart);
        ArrayList<String> xAXES = new ArrayList<>();
        ArrayList<Entry> y1=new ArrayList<>();
        ArrayList<Entry> y2 =new ArrayList<>();
        double x=0;
        int numdatapoint=2;

        for (int i = 0; i <numdatapoint ; i++) {
            float sinfunction = i;
            float confunction =i+2;
            x=x+0.1;
            y1.add(new Entry(sinfunction,i-1));
            y2.add(new Entry(confunction,i+2));
            xAXES.add(i,String.valueOf(i));
        }
        String [] xaxes =new String [xAXES.size()];
        for (int i = 0; i <xAXES.size() ; i++) {
            xaxes[i]=xAXES.get(i).toString();
        }
        List<ILineDataSet> lineDataSets = new ArrayList<>();
        LineDataSet lineDataSet = new LineDataSet(y1,"dataSet1");
        lineDataSet.setColor(Color.BLUE);
        LineDataSet lineDataSetY = new LineDataSet(y2,"dataset2");
        lineDataSetY.setColor(Color.RED);
        lineDataSets.add(lineDataSet);
        lineDataSets.add(lineDataSetY);
        LineData data = new LineData(xAXES,lineDataSets);
        data.setValueTextColor(Color.WHITE);
        data.setValueTextSize(9f);

        // set data
        lineChart.setData(data);
        lineChart.setVisibleXRangeMaximum(10f);}}

and XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
    <com.github.mikephil.charting.charts.LineChart
        android:layout_width="match_parent"
        android:id="@+id/line_chart"
        android:layout_height="match_parent"></com.github.mikephil.charting.charts.LineChart>

</LinearLayout>
Pang
  • 9,564
  • 146
  • 81
  • 122
0

Try the below line of code;

lineChart.getDescription().setEnabled(false);

Here is the link

Sohail
  • 303
  • 1
  • 10