MPAndroidChart - 如何显示的y值时,你的值为零? [英] MPAndroidChart - How to show the y-values when your value is zero?

查看:486
本文介绍了MPAndroidChart - 如何显示的y值时,你的值为零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MPAndroidChart 的 2.0.8发布

I using the 2.0.8 release of MPAndroidChart

我有一个问题,当y值都为零,并且条中不BARCHART所示。

I have a problem when the y-values are all zero, and the bars are not shown in the BarChart.

我查了一下示例项目:

不变code:

y的所有值只是改变在<零href=\"https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java#L260\">line 260 ,以

Just changing for all values of y are zero in the line 260, with

yVals1.add(new BarEntry(0, i));

但发生这种情况:

but this happens:

和在我的项目,在一些酒吧有非零值相同的情况,将显示所有的酒吧,是这样的:

And the same happens in my project, when some bars have nonzero values, all bars are displayed, like this:

但是,当所有的杆都为零,无杆被示出和只有一个标签显示在x轴

but when all the bars are zero, no bars are shown and only one label is shown on the x-axis

如何解决这一问题?

我需要的图表显示所有值的连值'Y'均为零。

I need the chart display all values even the values of 'y' are all zero.

推荐答案

我居然也得到了同样的问题,你。
我有一个柱状图,当所有的y值都为0,酒吧将不会显示在所有。
但是,如果有至​​少一个y值不是0时,条将出现了y值的连其余部分0

i was getting the same kind of problem as you. i have a bar chart, when all the y values are 0, the bar won't show at all. but if there is at least one y value that isn't 0, the bar will showed up even the rest of the y values is 0.

所以我觉得这是从MPAndroidChart一个bug。

so i think this is a bug from MPAndroidChart.

但我找到了一种方法来调整它一点点。
您需要设置固定的最大轴值,当所有的y值都为0。

but i found a way to tweak it a little bit. you need to set the fixed max axis value, when all the y values are 0.

这里是code设置固定轴最高值:

here is the code to set the fixed max axis value :

leftAxis.setAxisMaxValue(100f);

做的是,当所有的y值都为0,你将最大轴的值设置为100,但你可以,只要把它设置为其他值作为最大轴值不为0,并且柱形图会表现得如果所有的y值都为0。

by doing that, when all the y values are 0, you will set max axis value to 100, but you can set it to other value as long as the max axis value is not 0, and the bar chart will shown even if all the y values are 0.

希望这将解决您的问题。

hope it will fix your problem

这篇关于MPAndroidChart - 如何显示的y值时,你的值为零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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