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

时间:2015-08-24 07:25:41

标签: ios swift charts ios-charts

我正在使用神话般的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堂兄在哪里?!)

所以无论如何,那就是我所在的地方。我看过文档,但无济于事。帮助我吗?

4 个答案:

答案 0 :(得分:11)

customAxisMin在最新的图表中已弃用。

使用属性 axisMinValue 代替!

答案 1 :(得分:9)

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

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

答案 2 :(得分:8)

对于图表3(在图3.0.2中试用),这有效:

chartView.leftAxis.axisMinimum = 0

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

chartView.rightAxis.axisMinimum = 0

注意:我最初是以评论的形式写的,但我认为这应该是一个答案,可以让那些最终来自谷歌的人更容易找到。

答案 3 :(得分:0)

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

要使图形仅关注y值范围,请获取数据集LineChartData的最小值,如果要减去缓冲区以进行某些填充,则为

有人说过去曾经是“ linechart2.leftAxis.startAtZeroEnabled = false”,但这在代码中不再可见。