title: Scale X Axis MPAndroidCharts
body: <p>I have a simple line chart. I do not know how to make the x axis values to be properly scaled like the y axis values. Regardless of the values I input into the graph, the distance between the x values is always equidistant. </p>
  
  <p>Edited by adding the entire line chart code.</p>
  
  <pre><code>    setData();
  
      Legend l = mChart.getLegend();
  
  
      l.setForm(Legend.LegendForm.LINE);
  
      mChart.setDragEnabled(true);
      mChart.setScaleEnabled(true);
  
      YAxis leftAxis = mChart.getAxisLeft();
      leftAxis.removeAllLimitLines(); 
  
      leftAxis.enableGridDashedLine(10f, 10f, 0f);
      leftAxis.setDrawZeroLine(false);
  
  
      leftAxis.setDrawLimitLinesBehindData(true);
  
      mChart.getAxisRight().setEnabled(false);
  
      mChart.animateX(2000, Easing.EasingOption.EaseInOutQuart);
  
  
      mChart.invalidate();
  
      return view;
  }
  
  private ArrayList&lt;String&gt; setXAxisValues(){
      ArrayList&lt;String&gt; xVals = new ArrayList&lt;String&gt;();
      xVals.add(String.valueOf(x1));
  
      xVals.add(String.valueOf(x2));
      xVals.add(String.valueOf(x3));
      return xVals;
  }
  
  private ArrayList&lt;Entry&gt; setYAxisValues(){
      ArrayList&lt;Entry&gt; yVals = new ArrayList&lt;Entry&gt;();
      yVals.add(new Entry(0, y1));
      yVals.add(new Entry(1, y2));
      yVals.add(new Entry(2, y3));
  
      return yVals;
  }
  
  private void setData() {
      ArrayList&lt;String&gt; xVals = setXAxisValues();
  
      ArrayList&lt;Entry&gt; yVals = setYAxisValues();
  
      LineDataSet set1;
  
      set1 = new LineDataSet(yVals, yTitle);
  
      set1.setFillAlpha(110);
  
      ArrayList&lt;ILineDataSet&gt; dataSets = new ArrayList&lt;ILineDataSet&gt;();
      dataSets.add(set1); // add the datasets
      LineData data = new LineData(dataSets);
  
  
      String[] values = new String[] {String.valueOf(x1), String.valueOf(x2), String.valueOf(x3)};
      XAxis xAxis = mChart.getXAxis();
     xAxis.setGranularity(1f);
      mChart.setScaleEnabled(true);
  
      xAxis.setValueFormatter(new MyXAxisValueFormatted(values));
  
      mChart.getLegend().setTextColor(Color.WHITE);
      mChart.getXAxis().setTextColor(Color.WHITE);
      mChart.getAxisLeft().setTextColor(Color.WHITE);
      mChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
      mChart.setData(data);
  
  }
  </code></pre>
  
  <p>This is the XAxisValueFormatted class that may be the source of the problem:</p>
  
  <pre><code>public class MyXAxisValueFormatted implements  IAxisValueFormatter{
      private String[] mValues;
      public  MyXAxisValueFormatted(String[] values){
          this.mValues = values;
      }
  
      @Override
      public String getFormattedValue(float value, AxisBase axis) {
          return mValues[(int) value];
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/GFeSc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GFeSc.jpg" alt="enter image description here"></a></p>