MPAndroid BarChart label count and ValueFormatter not working properly

断了今生、忘了曾经 提交于 2019-12-11 05:55:22

问题


I have an issue with the BarChart and labels. The labels count is not correct. Even if I put a value directly:

xAxis.setLabelCount(5,true);

but what I get is only 4 labels. When I put 6 it becomes 5. It seems there is a bug.

Also the last item of the labels ( I am using a simple ValueFormatter) does not appear. If the number of labels equals the number of bars it repeats the first one twice even though I use the

xAxis.setGranularity(1f);
xAxis.setGranularityEnabled(true);

and the x values for each bar is 0, 1, 2, 3, 4.

Can anyone help me please?

Update

Look the image HERE


Here I am using a list of entries and the label is the data of the entry.

You see there are only 3 labels while the size of entries list is 4. and the first item repeated twice.

I make sure about the entries and there values :

        Log.d(TAG, "Size of categories : " + categoriesEntries.size());

        for (BarEntry e :
                categoriesEntries) {
            Log.d(TAG, e.getX() + " " +  e.getData().toString());
        }

The logcat output:

10-21 15:16:49.569 31194-31194/com.shamdroid.myfinancialassistant D/Statistics Activity: Size of categories : 4
10-21 15:16:49.569 31194-31194/com.shamdroid.myfinancialassistant D/Statistics Activity: 0.0 Study
10-21 15:16:49.569 31194-31194/com.shamdroid.myfinancialassistant D/Statistics Activity: 1.0 Home
10-21 15:16:49.569 31194-31194/com.shamdroid.myfinancialassistant D/Statistics Activity: 2.0 Car
10-21 15:16:49.569 31194-31194/com.shamdroid.myfinancialassistant D/Statistics Activity: 3.0 Schools

The ValueFormatter :

xAxis.setValueFormatter(new AxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {

                int i = (int) value;
                Log.d(TAG, value + "    " + i);

                return String.valueOf(categoriesEntries.get(i).getData());

            }

            @Override
            public int getDecimalDigits() {
                return 0;
            }
        });

回答1:


For others who have the same problem, I solve it by removing setLabelCount()



来源:https://stackoverflow.com/questions/40117894/mpandroid-barchart-label-count-and-valueformatter-not-working-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!