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

问题描述 投票:8回答:4

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

所以无论如何,这就是我所处的位置。我看过文档,但无济于事。帮我吗?

ios swift charts ios-charts
4个回答
8
投票

对于图表3(在图表3.0.2上试用),这适用于:

chartView.leftAxis.axisMinimum = 0

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

chartView.rightAxis.axisMinimum = 0

注意:我最初将其写为评论,但我认为这应该是一个答案,以便更容易找到最终来自谷歌的人。


11
投票

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

使用属性axisMinValue代替!


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;


0
投票
    linechart2.leftAxis.axisMinimum = chartDataline.getYMin() - 0.1

要使图形仅关注y值范围,请获取数据集LineChartData的最小值,以及是否要为某些填充减去缓冲区。

有些人说使用“linechart2.leftAxis.startAtZeroEnabled = false”,但不再在代码中看到。

© www.soinside.com 2019 - 2024. All rights reserved.