0

My problem is similar to this question SpreadSheetLight Column chart. However the problem is triggered when the number of rows outpace the number of columns, the chart automatically "invert" converting to a Row chart, where column chart is wanted.

The data set is generated via code however I add it for reference enter image description here

the resulting chart is this one:

enter image description here

However the intended result is this one (note the number of rows here is <= than number of columns, and that works as intended).

enter image description here

The code I use is pretty simple:

spreadsheet = new SLDocument();
var chart = spreadsheet.CreateChart("Dati", "A1", "M14");
chart.SetChartPosition(0, 0, 22, 10);
chart.PlotDataSeriesAsSecondaryLineChart(2, SLChartDataDisplayType.Normal, false);
spreadsheet.AddChart(cart);
spreadsheet.SaveAs(memoryStream);

Original attemp, with same behaviour was achieved via this code:

spreadsheet = new SLDocument();
var chart = spreadsheet.CreateChart("Dati", "A1", "M14");
chart.SetChartPosition(0, 0, 22, 10);
chart.SetChartType(SpreadsheetLight.Charts.SLLineChartType.Line);
spreadsheet.AddChart(cart);
spreadsheet.SaveAs(memoryStream);

Note that the problem cannot be fixed by "Transposing" (inverting rows with columns) because the problem is still present (in the opposite fashion). I could reproduce the behavior whenever the numer of rows is greater than the number of columns. Actually I have 13 columns and 14 ore more rows, but the problem is still present if I use 10 columns and 11 or more rows.

Hard-limiting the number of rows is not an option because a use case is comparison of 20 trend lines.

CoffeDeveloper
  • 7,961
  • 3
  • 35
  • 69

1 Answers1

0

After looking at the opensource code I finally found an answer. I need to do that

SLCreateChartOptions options = new()
{
     RowsAsDataSeries = true
};
spreadsheet = new SLDocument();
var chart = spreadsheet.CreateChart("Dati", "A1", "M14", options);
chart.SetChartPosition(0, 0, 22, 10);
chart.SetChartType(SpreadsheetLight.Charts.SLLineChartType.Line);
spreadsheet.AddChart(cart);
spreadsheet.SaveAs(memoryStream);

It bogus me why the developer choose to change default RowsAsDataSeries depending on number of columns and rows and not putting it "true" (or false) as default like Excell does. By the way very good library. And that concludes my 10 hours for this issue, hope it will be usefull to someone.

CoffeDeveloper
  • 7,961
  • 3
  • 35
  • 69