2015-08-24 61 views
5

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

有三种方法看起来很有前途(因为它们是相关的),但它们并不完全提供我正在寻找的行为类型。

1:Chart.setVisibleYRangeMaximum(如果只有它是Minimum ...)

2:Chart.setVisibleXRangeMaximum(再次没用......)

3:Chart.setVisibleXRangeMinimum(现在,这里是你的表妹YRange?!)

所以无论如何,这就是我所在的地方。我已阅读文档,但无济于事。帮我吗?

回答

9

customAxisMin在最新的排行榜已经过时了。

使用属性axisMinValue改为!

8

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

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

+0

在您的示例中:不要忘记设置startAtZeroEnabled = false,以便它在customAxisMin为负时也可以工作。使用最新版本的 –

+1

,不赞成使用startAtZeroEnabled,直接使用customAxisMin – Wingzero

+0

对于图表3,使用'chartView.leftAxis.axisMinimum = 0'。 –

1

对于图表3(试过图表3.0.2),这个工程:

chartView.leftAxis.axisMinimum = 0 

默认情况下是有rightAxis以及(至少对于条形图)和电网不会,如果对齐你不也成立:

chartView.rightAxis.axisMinimum = 0 

注:我最初写这个作为一个评论,但我认为它应该是一个答案,更容易找到谁在这里从谷歌结束了人。