title: MPAndroidChart - CustomValueFormatter renders values out of the Viewport
body: <p>I've been working with <code>HorizontalBarChart</code> <a href="https://github.com/PhilJay/MPAndroidChart" rel="nofollow noreferrer">MPAndroidChart</a> a few days ago, and ran into an issue while trying to use a custom ValueFormatter which converts the time from milliseconds into 12h format time. (08:50 AM) But as you can see in the picture below, the value gets clipped...</p>
  <p><img src="https://i.stack.imgur.com/gbPsW.png" alt="Screenshot" /></p>
  <p>Is there any possibility to set a padding for the chart on the right for the values to be visible?</p>
  <p>Here's the code which configures the chart:</p>
  <pre><code>private void initializeChart() {
      // Customize user interaction on chart
      mHorizontalBarChart.setTouchEnabled(false);
      mHorizontalBarChart.setPinchZoom(false);
      mHorizontalBarChart.setDragEnabled(false);
      // Customize chart's standard settings
      mHorizontalBarChart.setDrawGridBackground(false);
      mHorizontalBarChart.setDescription(&quot;&quot;);
      mHorizontalBarChart.setHighlightEnabled(false);
      mHorizontalBarChart.getLegend().setEnabled(false);
      Paint infoPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      infoPaint.setTextAlign(Paint.Align.CENTER);
      infoPaint.setTextSize(12f);
      mHorizontalBarChart.setPaint(infoPaint, Chart.PAINT_INFO);
  
      // Customize X axis
      XAxis xAxis = mHorizontalBarChart.getXAxis();
      xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
      xAxis.setTextSize(12f);
      xAxis.setDrawLabels(true);
      xAxis.setDrawAxisLine(false);
      xAxis.setDrawGridLines(false);
      xAxis.setAvoidFirstLastClipping(true);
  
      // Customize Y axis's
      // Left
      YAxis leftAxis = mHorizontalBarChart.getAxisLeft();
      leftAxis.setDrawLabels(false);
      leftAxis.setDrawAxisLine(false);
      leftAxis.setDrawGridLines(false);
      leftAxis.setDrawTopYLabelEntry(false);
      
      // Right
      YAxis rightAxis = mHorizontalBarChart.getAxisRight();
      rightAxis.setDrawLabels(false);
      rightAxis.setDrawAxisLine(false);
      rightAxis.setDrawGridLines(false);
      rightAxis.setDrawTopYLabelEntry(false);
      
  }
  </code></pre>
  <p>And here's the code which populates it:</p>
  <pre><code>private void setChartData(float range) {
      String[] daysOfWeek = new String[]{&quot;MO&quot;, &quot;TU&quot;, &quot;WE&quot;, &quot;TH&quot;, &quot;FR&quot;, &quot;SA&quot;, &quot;SU&quot;};
      ArrayList&lt;String&gt; xVals = new ArrayList&lt;String&gt;();
      for (int i = 0; i &lt; daysOfWeek.length; i++) {
          xVals.add(daysOfWeek[i]);
      }
  
      ArrayList&lt;BarEntry&gt; yVals1 = new ArrayList&lt;BarEntry&gt;();
  
      for (int i = 0; i &lt; daysOfWeek.length; i++) {
          float mult = (range + 1);
          float val = (float) (Math.random() * mult);
          yVals1.add(new BarEntry(val, i));
      }
  
      BarDataSet set1 = new BarDataSet(yVals1, &quot;DataSet&quot;);
      set1.setBarSpacePercent(35f);
  
      ArrayList&lt;BarDataSet&gt; dataSets = new ArrayList&lt;BarDataSet&gt;();
      dataSets.add(set1);
  
      BarData data = new BarData(xVals, dataSets);
      data.setValueTextSize(10f);
      data.setValueFormatter(new ValueFormatter() {
          @Override
          public String getFormattedValue(float value) {
              return value + &quot;some extra text&quot;;
          }
      });
  
      mHorizontalBarChart.setData(data);
  }
  </code></pre>
  <p>Any help is greatly appreciated.</p>
  <p>Code is used from the examples provided by @Philipp Jahoda.</p>
  <p><strong>EDIT: BASED ON Philipp's answer:</strong></p>
  <p>I used <code>setSpaceTop(float percent)</code> to adjust the space for the values of the BarData.</p>
  <pre><code>    // Customize Y axis's
      // Left
      YAxis leftAxis = mHorizontalBarChart.getAxisLeft();
      leftAxis.setDrawLabels(false);
      leftAxis.setDrawAxisLine(false);
      leftAxis.setDrawGridLines(false);
      leftAxis.setDrawTopYLabelEntry(false);
      leftAxis.setSpaceTop(20); // use these to adjust space for the BarData values
      // Right
      YAxis rightAxis = mHorizontalBarChart.getAxisRight();
      rightAxis.setDrawLabels(false);
      rightAxis.setDrawAxisLine(false);
      rightAxis.setDrawGridLines(false);
      rightAxis.setDrawTopYLabelEntry(false);
      rightAxis.setSpaceTop(20); // use these to adjust space for the BarData values
  </code></pre>
  <p>Code must be optimized though, this is just a quick test, but these suggestions worth tried out. Thanks again Philipp!</p>
  <p><img src="https://i.stack.imgur.com/01jsG.png" alt="Screenshot result" /></p>