MPAndroidChart如何设置y轴最小值和最大值或设置默认缩放?

时间:2022-09-26 18:53:49

I use MPAndroidChart to display the stock chart, but the Y line value is so close,the chart is like this MPAndroidChart如何设置y轴最小值和最大值或设置默认缩放?

我使用MPAndroidChart来显示股票图表,但是Y线的值很接近,图表是这样的。

I can use finger zoom like this way MPAndroidChart如何设置y轴最小值和最大值或设置默认缩放?

我可以这样使用手指缩放。

Which is I want the default looks like

我想要的是默认值?

Is there any way to set Y line max and min value or set default zoom.

是否有方法设置Y线最大值和最小值或设置默认缩放。

I tried the lib function , but it does not work

我尝试了lib函数,但它不起作用。

5 个解决方案

#1


22  

Take a look at the documentation of the YAxis. There are various methods that allow you to control the axis range.

桠溪看看文档。有很多方法可以控制轴的范围。

  • setStartAtZero(boolean enabled): If this is enabled, this axis will always have it's minimum value at zero (0), no matter which kind of data the chart displays.
  • setStartAtZero(布尔启用):如果启用了这个功能,这个axis将始终保持它的最小值为0(0),不管图表显示的是哪种数据。
  • setAxisMaxValue(float max): Set a custom maximum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
  • setAxisMaxValue(float max):为这个轴设置一个自定义最大值。如果设置,此值将不会根据提供的数据自动计算。
  • setAxisMinValue(float min): Set a custom minimum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
  • setAxisMinValue(float min):为这个轴设置一个自定义最小值。如果设置,此值将不会根据提供的数据自动计算。
  • setSpaceTop(float percent): Sets the top spacing (in percent of the total axis-range) of the highest value in the chart in comparison to the highest value on the axis.
  • setSpaceTop(浮动百分比):与轴上的最高值相比较,设置图表中最高值的顶部间距(在总坐标轴范围的百分比)。
  • setSpaceBottom(float percent): Sets the bottom spacing (in percent of the total axis-range) of the lowest value in the chart in comparison to the lowest value on the axis.
  • setSpaceBottom(浮动百分比):与轴上的最低值相比较,将图表中最低值的底部间距设置为最小值。

#2


9  

There is a kind of dependency between left and right axises. I had only right axis enabled and set

在左右轴之间有一种依赖关系。我只启用了右轴并设置了。

chart.getAxisRight().setStartAtZero(false);

but that didn't work till I set the same parameter to my leftYAxis, which was disabled. So I have now

但是直到我把相同的参数设置为我的左轴,它被禁用了。所以我现在已经

 chart.getAxisLeft().setStartAtZero(false);
 chart.getAxisRight().setStartAtZero(false);

edit:

编辑:

setStartAtZero is deprecated, the code recommends using setAxisMinimum instead.

setStartAtZero被弃用,代码建议使用setAxisMinimum代替。

 * This method is deprecated.
 * Use setAxisMinimum(...) / setAxisMaximum(...) instead.

#3


3  

You can also use the

你也可以使用。

mChart.setVisibleYRangeMaximum(150, AxisDependency.LEFT);

method to set highest visible value on y axis.

方法在y轴上设置最高可见值。

#4


1  

use setScaleMinima() and chart.moveViewToY(max), YAxis.AxisDependency.LEFT); is the best solution.

使用setScaleMinima()和chart.moveViewToY(max), YAxis.AxisDependency.LEFT);是最好的解决方案。

#5


0  

please try this , i am not sure that what your want.when i face minim zoom level in MPAndroidChart i used this method like this,

请试试这个,我不知道你想要什么。当我在MPAndroidChart中面对minim缩放级别时,我使用了这样的方法,

mChart.setPinchZoom(true); mChart.setScaleMinima(200,200); //for min and max value for zoom i Hope to be ok for your problem

mChart.setPinchZoom(真正的);mChart.setScaleMinima(200200);//对于最小值和最大值,我希望可以解决您的问题。

#1


22  

Take a look at the documentation of the YAxis. There are various methods that allow you to control the axis range.

桠溪看看文档。有很多方法可以控制轴的范围。

  • setStartAtZero(boolean enabled): If this is enabled, this axis will always have it's minimum value at zero (0), no matter which kind of data the chart displays.
  • setStartAtZero(布尔启用):如果启用了这个功能,这个axis将始终保持它的最小值为0(0),不管图表显示的是哪种数据。
  • setAxisMaxValue(float max): Set a custom maximum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
  • setAxisMaxValue(float max):为这个轴设置一个自定义最大值。如果设置,此值将不会根据提供的数据自动计算。
  • setAxisMinValue(float min): Set a custom minimum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
  • setAxisMinValue(float min):为这个轴设置一个自定义最小值。如果设置,此值将不会根据提供的数据自动计算。
  • setSpaceTop(float percent): Sets the top spacing (in percent of the total axis-range) of the highest value in the chart in comparison to the highest value on the axis.
  • setSpaceTop(浮动百分比):与轴上的最高值相比较,设置图表中最高值的顶部间距(在总坐标轴范围的百分比)。
  • setSpaceBottom(float percent): Sets the bottom spacing (in percent of the total axis-range) of the lowest value in the chart in comparison to the lowest value on the axis.
  • setSpaceBottom(浮动百分比):与轴上的最低值相比较,将图表中最低值的底部间距设置为最小值。

#2


9  

There is a kind of dependency between left and right axises. I had only right axis enabled and set

在左右轴之间有一种依赖关系。我只启用了右轴并设置了。

chart.getAxisRight().setStartAtZero(false);

but that didn't work till I set the same parameter to my leftYAxis, which was disabled. So I have now

但是直到我把相同的参数设置为我的左轴,它被禁用了。所以我现在已经

 chart.getAxisLeft().setStartAtZero(false);
 chart.getAxisRight().setStartAtZero(false);

edit:

编辑:

setStartAtZero is deprecated, the code recommends using setAxisMinimum instead.

setStartAtZero被弃用,代码建议使用setAxisMinimum代替。

 * This method is deprecated.
 * Use setAxisMinimum(...) / setAxisMaximum(...) instead.

#3


3  

You can also use the

你也可以使用。

mChart.setVisibleYRangeMaximum(150, AxisDependency.LEFT);

method to set highest visible value on y axis.

方法在y轴上设置最高可见值。

#4


1  

use setScaleMinima() and chart.moveViewToY(max), YAxis.AxisDependency.LEFT); is the best solution.

使用setScaleMinima()和chart.moveViewToY(max), YAxis.AxisDependency.LEFT);是最好的解决方案。

#5


0  

please try this , i am not sure that what your want.when i face minim zoom level in MPAndroidChart i used this method like this,

请试试这个,我不知道你想要什么。当我在MPAndroidChart中面对minim缩放级别时,我使用了这样的方法,

mChart.setPinchZoom(true); mChart.setScaleMinima(200,200); //for min and max value for zoom i Hope to be ok for your problem

mChart.setPinchZoom(真正的);mChart.setScaleMinima(200200);//对于最小值和最大值,我希望可以解决您的问题。