diff --git a/Source/Charts/Components/AxisBase.swift b/Source/Charts/Components/AxisBase.swift index cdf4f1099c..95c721de12 100644 --- a/Source/Charts/Components/AxisBase.swift +++ b/Source/Charts/Components/AxisBase.swift @@ -50,7 +50,7 @@ open class AxisBase: ComponentBase /// This is useful especially for grouped BarChart. open var centerAxisLabelsEnabled: Bool { - get { return _centerAxisLabelsEnabled && entryCount > 1 } + get { return _centerAxisLabelsEnabled && entryCount > 0 } set { _centerAxisLabelsEnabled = newValue } } diff --git a/Source/Charts/Renderers/AxisRendererBase.swift b/Source/Charts/Renderers/AxisRendererBase.swift index 8fb7357d23..a98019f78a 100644 --- a/Source/Charts/Renderers/AxisRendererBase.swift +++ b/Source/Charts/Renderers/AxisRendererBase.swift @@ -129,9 +129,8 @@ open class AxisRendererBase: Renderer // Use one order of magnitude higher, to avoid intervals like 0.9 or 90 interval = floor(10.0 * Double(intervalMagnitude)) } - - let centeringEnabled = axis.centerAxisLabelsEnabled - var n = centeringEnabled ? 1 : 0 + + var n = 1 // force label count if axis.isForceLabelsEnabled @@ -158,7 +157,7 @@ open class AxisRendererBase: Renderer var first = interval == 0.0 ? 0.0 : ceil(yMin / interval) * interval - if centeringEnabled + if axis.centerAxisLabelsEnabled { first -= interval } @@ -204,16 +203,12 @@ open class AxisRendererBase: Renderer axis.decimals = 0 } - if centeringEnabled + if axis.centerAxisLabelsEnabled { axis.centeredEntries.reserveCapacity(n) axis.centeredEntries.removeAll() - var offset: Double = 0.0 - if axis.entries.count > 1 - { - offset = (axis.entries[1] - axis.entries[0]) / 2.0 - } + let offset: Double = interval / 2.0 for i in 0 ..< n {