diff --git a/public/app/plugins/panel/timeseries/plugins/OutsideRangePlugin.tsx b/public/app/plugins/panel/timeseries/plugins/OutsideRangePlugin.tsx index 721c9f45bb3..d088f9f9d63 100644 --- a/public/app/plugins/panel/timeseries/plugins/OutsideRangePlugin.tsx +++ b/public/app/plugins/panel/timeseries/plugins/OutsideRangePlugin.tsx @@ -34,11 +34,26 @@ export const OutsideRangePlugin: React.FC = ({ con } // Time values are always sorted for uPlot to work - const first = timevalues[0]; - const last = timevalues[timevalues.length - 1]; + let i = 0, + j = timevalues.length - 1; + + while (i <= j && timevalues[i] == null) { + i++; + } + + while (j >= 0 && timevalues[j] == null) { + j--; + } + + const first = timevalues[i]; + const last = timevalues[j]; const fromX = timeRange.min; const toX = timeRange.max; + if (first == null || last == null) { + return null; + } + // (StartA <= EndB) and (EndA >= StartB) if (first <= toX && last >= fromX) { return null;