Mpandroidchart: X Axis Labels being cut off horizontally

Created on 6 Apr 2016  路  9Comments  路  Source: PhilJay/MPAndroidChart

I have a line chart with the X Axis position set to BOTTOM.

A visual issue occurs where some labels are cut off horizontally. Adding a margin or extra padding does not resolve this issue. I'm confused at to why the first label appears correctly and the rest do not.

It's worth noting that I'm using a custom font for the chart level TypeFace.

chartxaxisissue

Using version 2.2.4

Potentially related to Issue #1484

Most helpful comment

Have you tried modifying the offsets?

xAxis.setYOffset(...) or

chart.setExtraBottomOffset(...)

All 9 comments

Have you tried modifying the offsets?

xAxis.setYOffset(...) or

chart.setExtraBottomOffset(...)

Ah I just see, it's only for some of the labels. That's a known issue, should be fixed soon.

hello, this is because the size of the letters are not the same. The return of getTextBounds method for String Mar 30 and 01 Apr, are different as you can see

private static void sizeLetter(Paint paint){ String[] letters = {"30 Mar", "01 Apr"}; Rect rect = new Rect(); for(int i = 0; i < letters.length; i++){ paint.getTextBounds(letras[i], 0, letters[i].length(), rect); Log.i("INFO", "LineHeight LETTER " + letters[i] + " - " + rect.height()); } }

I too face the same issue

I used the thadeubatista's method to make X Axis Labels show completed, but the text still not aligned....especially, the X Axis Labels is Chinese.

hi cizkey, this method above have a issue. I sent a new version, but was not accepted. If you want , I can send you the new method

I still encounter the issue after changing the font size to the bigger but setExtraBottomOffset helps

I have the same problem when I change the text values font.
When I show the chart legend, that didn't happen, so I set an invisible legend which resolve this issue (this is not a real solution, only a temporal fix)

 private void setTransparentLegend(LineChart mChart, Context context) {
        Legend legend = mChart.getLegend();
        legend.setTextSize(12f);
        legend.setXEntrySpace(5f);

        LegendEntry legendEntry = new LegendEntry("", Legend.LegendForm.CIRCLE, 12, 1, null, context.getResources().getColor(android.R.color.white));
        List<LegendEntry> legendArray = new ArrayList<>();
        legendArray.add(legendEntry);
        legend.setCustom(legendArray);
    }

Another option is seen here

chart.setExtraOffsets(30, 30, 30, 30);

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Giammaofwar picture Giammaofwar  路  3Comments

SutharRohit picture SutharRohit  路  3Comments

botondbutuza picture botondbutuza  路  3Comments

tsengvn picture tsengvn  路  3Comments

rohitkumarbhagat picture rohitkumarbhagat  路  3Comments