From 316eeadedca2019e53669a419e607e233c177600 Mon Sep 17 00:00:00 2001 From: gxbag Date: Wed, 4 Dec 2019 13:31:57 +0100 Subject: [PATCH] Fix bug in Series It is possible that Series has no elements. That means that Series[0] cannot be accessed. It was the case in my Excel file that I was working on. I only have ScatterCharts in my Excel file, thus, if the other charts also assume that Series always has elements, this will fail in those cases. --- EPPlus/Drawing/Chart/ExcelScatterChart.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EPPlus/Drawing/Chart/ExcelScatterChart.cs b/EPPlus/Drawing/Chart/ExcelScatterChart.cs index 3d4ffe62f..4d31edf41 100644 --- a/EPPlus/Drawing/Chart/ExcelScatterChart.cs +++ b/EPPlus/Drawing/Chart/ExcelScatterChart.cs @@ -135,7 +135,7 @@ internal override eChartType GetChartType(string name) { if (ScatterStyle==eScatterStyle.LineMarker) { - if (((ExcelScatterChartSerie)Series[0]).Marker == eMarkerStyle.None) + if (Series.Count > 0 && ((ExcelScatterChartSerie)Series[0]).Marker == eMarkerStyle.None) { return eChartType.XYScatterLinesNoMarkers; } @@ -153,7 +153,7 @@ internal override eChartType GetChartType(string name) } else if (ScatterStyle == eScatterStyle.SmoothMarker) { - if (((ExcelScatterChartSerie)Series[0]).Marker == eMarkerStyle.None) + if (Series.Count > 0 && ((ExcelScatterChartSerie)Series[0]).Marker == eMarkerStyle.None) { return eChartType.XYScatterSmoothNoMarkers; }