         
         CGContextSaveGState(context)
         
-        guard let
-            entryFrom = dataSet.entryForXIndex(self.minX),
-            entryTo = dataSet.entryForXIndex(self.maxX)
-            else { return }
-        
-        let diff = (entryFrom == entryTo) ? 1 : 0
-        let minx = max(dataSet.entryIndex(entry: entryFrom) - diff, 0)
-        let maxx = min(max(minx + 2, dataSet.entryIndex(entry: entryTo) + 1), entryCount)
+        var fromEnty: ChartDataEntry?
+        var toEntry: ChartDataEntry?
+        for x in (self.minX...self.maxX) {
+            let entry = dataSet.entryForXIndex(x)
+            if let e = entry {
+                if fromEnty == nil {
+                    fromEnty = e
+                }
+                toEntry = e
+            } else if toEntry != nil {
+                break
+            }
+        }
+        
+        guard let fromIndex = fromEnty.map({dataSet.entryIndex(entry: $0) }),
+            toIndex = toEntry.map({dataSet.entryIndex(entry: $0) })else { return }
+        
+        let diff = (fromIndex == toIndex) ? 1 : 0
+        let minx = max(fromIndex - diff, 0)
+        let maxx = min(max(minx + 2, toIndex + 1), entryCount)
         
         // more than 1 color
         if (dataSet.colors.count > 1)

        
        let entryCount = dataSet.entryCount
        
        guard let
            entryFrom = dataSet.entryForXIndex(self.minX),
            entryTo = dataSet.entryForXIndex(self.maxX)
            else { return }
        
        let diff = (entryFrom == entryTo) ? 1 : 0
        let minx = max(dataSet.entryIndex(entry: entryFrom) - diff, 0)
        let maxx = min(max(minx + 2, dataSet.entryIndex(entry: entryTo) + 1), entryCount)
        
        let phaseX = animator.phaseX
        let phaseY = animator.phaseY

                prevPrev = prev
                prev = cur
                cur = next
                next = dataSet.entryForIndex(j + 1) ?? cur
                
                if next == nil { break }
                
