title: Create Line Chart in Android using MPAndroidChart library
body: <p>I want to create a chart as shown in the image. Till now I have tried it to achieve using <a href="https://github.com/PhilJay/MPAndroidChart" rel="nofollow noreferrer">MPAndroidChart</a>.</p>
  <p><a href="https://i.stack.imgur.com/ujrgB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ujrgB.png" alt="Line Chart" /></a></p>
  <p>However, I tried so far and unable to make it.</p>
  <p>My codes are as below:</p>
  <p><strong>Layout:</strong></p>
  <pre class="lang-xml prettyprint-override"><code>&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;fill_parent&quot;
      android:layout_height=&quot;fill_parent&quot;
      android:background=&quot;#ffffff&quot;
      android:orientation=&quot;vertical&quot;
      tools:ignore=&quot;HardcodedText&quot;&gt;
  
      &lt;com.github.mikephil.charting.charts.LineChart
          android:id=&quot;@+id/lineChart&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot; /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  <p><strong>Activity File:</strong></p>
  <pre class="lang-java prettyprint-override"><code>package com.app.androidchart;
      
  import android.graphics.Color;
  import android.os.Bundle;
  
  import androidx.appcompat.app.AppCompatActivity;
      
  import com.github.mikephil.charting.charts.LineChart;
  import com.github.mikephil.charting.components.XAxis;
  import com.github.mikephil.charting.components.YAxis;
  import com.github.mikephil.charting.data.Entry;
  import com.github.mikephil.charting.data.LineData;
  import com.github.mikephil.charting.data.LineDataSet;
  import com.github.mikephil.charting.formatter.IndexAxisValueFormatter;
      
  import java.util.ArrayList;
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity {
         
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          drawLineChart();
      }
  
      private void drawLineChart() {
          LineChart lineChart = findViewById(R.id.lineChart);
          List&lt;Entry&gt; lineEntries = getDataSet();
          LineDataSet lineDataSet = new LineDataSet(lineEntries, &quot;Work&quot;);
          lineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
          lineDataSet.setHighlightEnabled(true);
          lineDataSet.setLineWidth(2);
          lineDataSet.setColor(Color.RED);
          lineDataSet.setCircleColor(Color.YELLOW);
          lineDataSet.setCircleRadius(6);
          lineDataSet.setCircleHoleRadius(3);
          lineDataSet.setDrawCircles(false);
          lineDataSet.setDrawHighlightIndicators(true);
          lineDataSet.setHighLightColor(Color.RED);
          lineDataSet.setValueTextSize(12);
          lineDataSet.setValueTextColor(Color.DKGRAY);
          lineDataSet.setMode(LineDataSet.Mode.STEPPED);
  
          LineData lineData = new LineData(lineDataSet);
          lineChart.getDescription().setTextSize(12);
          lineChart.getDescription().setEnabled(false);
          lineChart.setDrawMarkers(false);
          lineChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
          lineChart.animateY(1000);
          lineChart.getXAxis().setGranularityEnabled(true);
          lineChart.getXAxis().setGranularity(1.0f);
          lineChart.setData(lineData);
  
          ArrayList&lt;String&gt; xAxisLabel = new ArrayList&lt;&gt;();
          xAxisLabel.add(&quot;Rest&quot;);
          xAxisLabel.add(&quot;Work&quot;);
          xAxisLabel.add(&quot;2-up&quot;);
  
          XAxis xAxis = lineChart.getXAxis();
          xAxis.setAxisMaximum(3);
          xAxis.setGranularity(1f);
          xAxis.setValueFormatter(new IndexAxisValueFormatter(xAxisLabel) {
              @Override
              public String[] getValues() {
                  return super.getValues();
              }
          });
  
          YAxis yAxis = lineChart.getAxisLeft();
          yAxis.setAxisMinimum(0);
          yAxis.setAxisMaximum(24);
  
          lineChart.getAxisRight().setEnabled(false);
  
          lineChart.invalidate();
  
      }
  
      private List&lt;Entry&gt; getDataSet() {
          List&lt;Entry&gt; lineEntries = new ArrayList&lt;&gt;();
          lineEntries.add(new Entry(0, 4));
          lineEntries.add(new Entry(1, 3));
          lineEntries.add(new Entry(2, 6));
          lineEntries.add(new Entry(3, 8));
          lineEntries.add(new Entry(4, 2));
          lineEntries.add(new Entry(5, 3));
          lineEntries.add(new Entry(6, 1));
          return lineEntries;
      }
  
  }
  </code></pre>
  <p>Above is the entire code to achieve as per the shared image.</p>
  <p>I want solutions for the below things:</p>
  <ul>
  <li>Set X-Axis at the left side</li>
  <li>Set Y-Axis at the top side</li>
  <li>Assign data in which the X-axis has 3 items and Y-Axis has 24 (here I didn't find any method inside the Entry class of MPAndroid Chart.)</li>
  </ul>
  <p>Please suggest me some solutions.</p>
  <p>Thanks.</p>