MPAndroid BarChart标签计数和ValueFormatter无法正常工作 [英] MPAndroid BarChart label count and ValueFormatter not working properly

查看:501
本文介绍了MPAndroid BarChart标签计数和ValueFormatter无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在BarChart和标签上有问题.标签计数不正确.即使我直接输入值:

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);

但是我得到的只有4个标签.当我放6时,它变成5.似乎有一个错误.

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

标签的最后一项(我使用的是简单的ValueFormatter)也不会出现.如果标签的数量等于小节的数量,即使我使用

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);

,每个条形的x值为01234.

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

有人可以帮我吗?

更新

查看图像 此处


我在这里使用条目列表,标签是条目的数据.

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

您看到只有3个标签,而条目列表的大小是4.第一个项目重复了两次.

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());
        }

logcat输出:

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

ValueFormatter:

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;
            }
        });

推荐答案

对于其他有相同问题的人,我可以通过删除setLabelCount()来解决它

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

这篇关于MPAndroid BarChart标签计数和ValueFormatter无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆