From 8c28cfa5dcbef6e528bba5ccdd6247ff1c372475 Mon Sep 17 00:00:00 2001 From: Scalman Date: Mon, 29 Jul 2019 04:19:24 +0200 Subject: [PATCH] fixed stacked chart bug when there are different stacks on columns. (#4029) fix #3659 * fixed stacked chart bug when there are different stacks on columns. * added empty array check --- Source/Charts/Renderers/BarChartRenderer.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Charts/Renderers/BarChartRenderer.swift b/Source/Charts/Renderers/BarChartRenderer.swift index 6b192051bb..e675ba2215 100644 --- a/Source/Charts/Renderers/BarChartRenderer.swift +++ b/Source/Charts/Renderers/BarChartRenderer.swift @@ -867,9 +867,12 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer } else { stackLabel = nil } - + + //Handles empty array of yValues + let yValue = vals.isEmpty ? 0.0 : vals[idx % vals.count] + elementValueText = dataSet.valueFormatter?.stringForValue( - vals[idx % stackSize], + yValue, entry: e, dataSetIndex: dataSetIndex, viewPortHandler: viewPortHandler) ?? "\(e.y)"