2015-08-24 62 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 

注:我最初寫這個作爲一個評論,但我認爲它應該是一個答案,更容易找到誰在這裏從谷歌結束了人。