iOS图表-设置最小y轴范围



我正在使用出色的iOS图表库(https://github.com/danielgindi/ios-charts)我很难在文档中找到任何支持这种行为的东西。我想强制y轴始终显示0-35的范围。目前,如果我在(0,9(处只有一个数据条目,y轴将显示其范围为0-9。然而,当我在(1,32(处添加另一个条目时,我突然可以在35处看到图表的顶部。

有三种方法看起来很有前景(因为它们是相关的(,但它们并不能提供我想要的行为类型。

1:Chart.setVisibleYRangeMaximum(如果是Minimum就好了…(

2:Chart.setVisibleXRangeMaximum(又没用了…(

3:Chart.setVisibleXRangeMinimum(现在你的YRange表亲在哪里?!(

不管怎样,这就是我现在的处境。我读过文件,但没有用。帮我吗?

对于图表3(在图表3.0.2上试用(,这是有效的:

chartView.leftAxis.axisMinimum = 0

默认情况下,也有一个右轴(至少对于条形图(,如果你不设置,网格将不会对齐:

chartView.rightAxis.axisMinimum = 0

注意:我最初是作为评论写的,但我认为这应该是一个更容易为谷歌用户找到的答案

customAxisMin在最新图表中不推荐使用。

请改用属性axisMinValue

看看下面的属性。应该能够解决你的问题。

/// A custom minimum value for this axis. 
/// If set, this value will not be calculated automatically depending on the provided data. 
/// Use resetCustomAxisMin() to undo this. 
/// Do not forget to set startAtZeroEnabled = false if you use this method.
/// Otherwise, the axis-minimum value will still be forced to 0.
public var customAxisMin = Double.NaN
/// Set a custom maximum value for this axis. 
/// If set, this value will not be calculated automatically depending on the provided data. 
/// Use resetCustomAxisMax() to undo this.
public var customAxisMax = Double.NaN
/// if true, the y-label entries will always start at zero
public var startAtZeroEnabled = true

例如:

_chartView.leftAxis.customAxisMax = 35;
_chartView.leftAxis.customAxisMin = 0;

_chartView.leftAxis.startAtZeroEnabled = YES;

    linechart2.leftAxis.axisMinimum = chartDataline.getYMin() - 0.1

要使图形只关注y值范围,请获取数据集LineChartData的最小值,如果您想减去一些填充的缓冲区。

有些人说过去有"linechart2.eftAxis.startAtZeroEnabled=false",但在代码中已经看不到了。

最新更新