Fix iterator being reseted and causing an implicit endless loop in charts

fixes #4014