MPAndroidChart RadarChart minimizes itself

I have some problems with RadarChart tags. In particular, if I use long texts (for example, 15-20 characters), and the available space is not too large, the chart crashes and the labels are placed inside the collapsed chart (but there is clearly more free space).

I tried to use a ValueFormatter for the label axis, which truncates the labels if they are longer than 5 characters, but as I can see, the calculation of the size of the chart is based on the full text of the label, since the chart crashed the same way I described it 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 photos to clarify the problem. Charts are displayed inside CardView , and, as you can see, there is a lot of free space on all sides. The first two pictures are taken with the ValueFormatter set, the last two without it.

Description

Description

Description

Description

+5
source share
1 answer

You probably have some errors, here are some solutions:

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

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

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

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

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

0
source

Source: https://habr.com/ru/post/1244958/


All Articles