diff --git a/Charts/Classes/Components/ChartYAxis.swift b/Charts/Classes/Components/ChartYAxis.swift index 6c23b76446..2646ed2678 100644 --- a/Charts/Classes/Components/ChartYAxis.swift +++ b/Charts/Classes/Components/ChartYAxis.swift @@ -103,6 +103,14 @@ public class ChartYAxis: ChartAxisBase /// **default**: 0.0 (no maximum specified) public var maxWidth = CGFloat(0) + /// if true, axis values will be repeated + public var allowRepeatedValues = false + + /// the minimum diference value of the axis values + /// + /// **default**: 1 + public var granuality = Double(1.0) + public override init() { super.init() diff --git a/Charts/Classes/Renderers/ChartYAxisRenderer.swift b/Charts/Classes/Renderers/ChartYAxisRenderer.swift index d2ee98e4a7..5171f5681a 100644 --- a/Charts/Classes/Renderers/ChartYAxisRenderer.swift +++ b/Charts/Classes/Renderers/ChartYAxisRenderer.swift @@ -70,6 +70,10 @@ public class ChartYAxisRenderer: ChartAxisRendererBase let rawInterval = range / Double(labelCount) var interval = ChartUtils.roundToNextSignificant(number: Double(rawInterval)) + if !_yAxis.allowRepeatedValues + { + interval = interval < _yAxis.granuality ? _yAxis.granuality : interval + } let intervalMagnitude = pow(10.0, round(log10(interval))) let intervalSigDigit = (interval / intervalMagnitude) if (intervalSigDigit > 5) diff --git a/ChartsDemo/Classes/Demos/CombinedChartViewController.m b/ChartsDemo/Classes/Demos/CombinedChartViewController.m index f05827fc39..4ffbb49171 100644 --- a/ChartsDemo/Classes/Demos/CombinedChartViewController.m +++ b/ChartsDemo/Classes/Demos/CombinedChartViewController.m @@ -54,9 +54,11 @@ - (void)viewDidLoad ChartYAxis *rightAxis = _chartView.rightAxis; rightAxis.drawGridLinesEnabled = NO; + rightAxis.granuality = 0.1; ChartYAxis *leftAxis = _chartView.leftAxis; leftAxis.drawGridLinesEnabled = NO; + leftAxis.granuality = 0.1; ChartXAxis *xAxis = _chartView.xAxis; xAxis.labelPosition = XAxisLabelPositionBothSided; diff --git a/ChartsDemo/Classes/Demos/LineChart2ViewController.m b/ChartsDemo/Classes/Demos/LineChart2ViewController.m index bffeb7bd4d..ff6d1b52e0 100644 --- a/ChartsDemo/Classes/Demos/LineChart2ViewController.m +++ b/ChartsDemo/Classes/Demos/LineChart2ViewController.m @@ -75,6 +75,7 @@ - (void)viewDidLoad leftAxis.labelTextColor = [UIColor colorWithRed:51/255.f green:181/255.f blue:229/255.f alpha:1.f]; leftAxis.customAxisMax = 200.0; leftAxis.drawGridLinesEnabled = YES; + leftAxis.allowRepeatedValues = false; ChartYAxis *rightAxis = _chartView.rightAxis; rightAxis.labelTextColor = UIColor.redColor; @@ -82,6 +83,7 @@ - (void)viewDidLoad rightAxis.startAtZeroEnabled = NO; rightAxis.customAxisMin = -200.0; rightAxis.drawGridLinesEnabled = NO; + rightAxis.allowRepeatedValues = true; _sliderX.value = 19.0; _sliderY.value = 30.0; diff --git a/ChartsDemo/Classes/Demos/LineChart2ViewController.xib b/ChartsDemo/Classes/Demos/LineChart2ViewController.xib index eb70c43187..895b559e64 100644 --- a/ChartsDemo/Classes/Demos/LineChart2ViewController.xib +++ b/ChartsDemo/Classes/Demos/LineChart2ViewController.xib @@ -1,7 +1,8 @@ - + - + +