Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart RadarChart collapses itself

I have some problems with RadarChart labels. Specifically, if I use long texts (e.g. 15-20 chars), and the available space is not too big, the chart gets collapsed and the labels are positioned inside the collapsed chart (but there is clearly more space available).

I tried to use ValueFormatter for the label axis that truncates labels if they are longer than 5 chars, but as I see, the chart size calculaction is based on the full label text, as the chart got collapsed the same way I described before.

XAxis xAxis = radarChart.getXAxis();
xAxis.setValueFormatter(new XAxisValueFormatter() {
    @Override
    public String getXValue(String original, int index, ViewPortHandler viewPortHandler) {
        return original.length() > 5 ? original.substring(0, 5) + "…" : original;
    }
});

Here are some pictures to clarify the problem. The charts are displayed inside CardViews and as you can see, there is plenty of space remaining on all sides. The first two pictures are taken with the ValueFormatter set, the last two are without it.

Description

Description

Description

Description

like image 897
Sleeper9 Avatar asked May 09 '16 10:05

Sleeper9


1 Answers

Probably you are having some mistakes, here are some solutions:

1) Set your radar data after you set your RadarChart parameters then call invalidate();

2) Set AxisMinimum and AxisMaximum in radarChart.getXAxis() and radarChart.getYAxis()

3) Call yAxis.calculate(min,max) after step 2;

4) If needed use radarChart.setExtraOffsets(?,?,?,?)

I am using com.github.PhilJay:MPAndroidChart:v3.0.1

like image 163
Guilherme Simão Couto Avatar answered Nov 01 '22 06:11

Guilherme Simão Couto