力BARCHART Y轴标签是整数?整数、标签、BARCHART

2023-09-07 16:07:25 作者:转角再相遇

我已经使用MPAndroidChart创造了一个柱状图,我动态输入数据。这意味着,我需要还可以动态地确定我的Y轴。我所有的数据都被重新psented为整数$ P $,但Y轴有时显示的传说与1小数点十进制值。

I've created a BarChart using MPAndroidChart and I'm entering the data dynamically. This means that I need my Y axis to also be determined dynamically. All of my data is represented as integers, however the Y axis is sometimes displaying the legend as decimal values with 1 decimal point.

我试图使用ValueFormatter圆的值,但问题是,有时Y值不在整数值的位置(例如,0.8,1.6,2.4等)。所以,如果我只是编辑这些是整数,他们不会在正确的位置。

I've attempted to use a ValueFormatter to round the values, but the problem is that sometimes the Y values aren't at integer value locations (ex. 0.8,1.6,2.4,etc). Therefore, if I just edit these to be integers they won't be in the right location.

反正是有,我可以在整数位置强制BARCHART只显示值?它的确定,如果它跳过了一些,其实我是想当值获得大​​的。

Is there anyway that I can force the BarChart to only display values at Integer locations? Its ok if it skips some, in fact I want it to when the values get large.

编辑:当我说的整数不在正确的位置,我的意思是,一旦我修改每个标签显示它们是什么不是正确。在我的例子我有5条显示的值3,4,2,3,2。第一个图像是默认,二是一旦我编辑使用值格式图像:

When I said that the integers aren't in the right locations, I meant that once I modify what each label displays they aren't 'correct'. In my example I have 5 bars displaying the values 3,4,2,3,2. The first image is the 'default', the second is the image once I've edited the value formatter using:

myBarChart.getYLabels().setFormatter(new ValueFormatter()
{
    @Override
    public String getFormattedValue(float v)
    {
        return ((int) v)+"";
    }
});

正如我们从这些图像看,我的整数值不是他们应该是(并有两个闪)。在这个例子中我除了它显示的值0,1,2,3,4。如果我有更多的数据我希望这将是足够聪明,只显示什么样的价值观我有空间,所以对于例子,如果数据包含0-50值会显示类似0,10,20,30 ,40,50或可能0,15,30,45等。

As we can see from these images, my integer values are not where they should be (and there are two '2s'). In this example I'd except it to display the values 0,1,2,3,4. If I have a lot more data I'm hoping it would be smart enough to only show what values I have room for, so for examples if the data contains values of 0-50 it would show something like 0,10,20,30,40,50 or possibly 0,15,30,45, etc.

推荐答案

还好吧,现在我明白你的问题。问题是, Y轴(YLabels)决定的位数因此步骤每个标签的自动

Allright, now I see your problem. THe problem is that the YAxis (YLabels) determines the number of digits and thus the steps between each label automatically.

不幸的是,的目前无法自定义轴如何计算本身还是设置自定义标签。

Unfortunately it's currently not possible to customize how the axis computes itself or set custom labels.

我正在考虑到在未来,其中用户可以自定义哪些值被绘制成轴标签添加这样的功能。

I am considering to add such a feature in the future, where the user can self define which values are drawn as the axis labels.

只是一个提示:

这包含所有轴标签的 mEntries 数组是公共的。所以一般来说,你可以修改它,它已经被创建后。但是,我绝对不知道轴将如何表现,如果你手动修改它。

The mEntries array that holds all the axis labels is public. So in general, you could modify it after it has been created. However, I am absolutely not sure how the axis will behave if you manually modify it.

但也许它值得一试:-)https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartLib/src/com/github/mikephil/charting/components/YAxis.java

But maybe its worth a try :-) https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartLib/src/com/github/mikephil/charting/components/YAxis.java