                     var xVals = data.xVals
                     let pds = dataSet as! PieChartDataSet
                     
-                    for (var j = 0; j < clrs.count && j < entryCount && j < xVals.count; j++)
+                    for j in 0..<min(clrs.count, entryCount, xVals.count)
                     {
                         labels.append(xVals[j])
                         colors.append(clrs[j])

                    let bds = dataSet as! BarChartDataSet
                    var sLabels = bds.stackLabels
                    
                    for (var j = 0; j < clrs.count && j < bds.stackSize; j++)
                    {
                        labels.append(sLabels[j % sLabels.count])
                        colors.append(clrs[j])

                else
                { // all others
                    
                    for j in 0..<min(clrs.count, entryCount)
                    {
                        // if multiple colors are set for a DataSet, group them
                        if (j < clrs.count - 1 && j < entryCount - 1)
