iOS 图表 - 设置最小 y 轴范围
iOS Charts - set minimum y axis range
我正在使用很棒的 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
表弟呢?!)
所以无论如何,这就是我所在的位置。我已阅读文档但无济于事。帮帮我吗?
看看下面的属性。应该可以解决你的问题。
/// 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;
customAxisMin
在最新的图表中已弃用。
改用属性axisMinValue
!
对于图表 3(在图表 3.0.2 上试过),这有效:
chartView.leftAxis.axisMinimum = 0
默认情况下还有一个 rightAxis(至少对于条形图),如果您不设置,网格将不会对齐:
chartView.rightAxis.axisMinimum = 0
注意:我最初是作为评论写的,但我认为对于从 Google. 最终来到这里的人来说,这应该是一个更容易找到的答案
linechart2.leftAxis.axisMinimum = chartDataline.getYMin() - 0.1
要使图形仅关注值的 y 范围,请获取数据集 LineChartData 的最小值,如果要减去缓冲区以进行一些填充。
有些人说曾经有 "linechart2.leftAxis.startAtZeroEnabled = false" 但在代码中已经看不到了。
我正在使用很棒的 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
表弟呢?!)
所以无论如何,这就是我所在的位置。我已阅读文档但无济于事。帮帮我吗?
看看下面的属性。应该可以解决你的问题。
/// 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;
customAxisMin
在最新的图表中已弃用。
改用属性axisMinValue
!
对于图表 3(在图表 3.0.2 上试过),这有效:
chartView.leftAxis.axisMinimum = 0
默认情况下还有一个 rightAxis(至少对于条形图),如果您不设置,网格将不会对齐:
chartView.rightAxis.axisMinimum = 0
注意:我最初是作为评论写的,但我认为对于从 Google. 最终来到这里的人来说,这应该是一个更容易找到的答案
linechart2.leftAxis.axisMinimum = chartDataline.getYMin() - 0.1
要使图形仅关注值的 y 范围,请获取数据集 LineChartData 的最小值,如果要减去缓冲区以进行一些填充。
有些人说曾经有 "linechart2.leftAxis.startAtZeroEnabled = false" 但在代码中已经看不到了。