title: Adding multiple charts to EPPlus Worksheet, struggling to get layout correct
body: <p>I'm currently creating Excel spreadsheets via EPPlus, the data is basically split into, section, questions, responses, with each being a subset of the other, I don't know how many questions each section might have, so everything needs to be done via loops. </p>
  
  <p>What I want is for the document to contain a worksheet that shows a chart for each question giving a breakdown of the answers.</p>
  
  <p>I'm extremely close to getting it working correctly but something in my code is causing issues and I can't work out what it is.</p>
  
  <p>The data I'm currently working with holds 10 questions, all the charts are drawn but the very last one is positioned directly over the top of the first. I'm also having issues with getting the text results positioned correctly but since the code for that depends on that for the charts I'm hoping that sorting the charts will help me sort the results.</p>
  
  <p>Here is my code:</p>
  
  <pre><code> Int32 chartPaddingX = 50;
   Int32 chartPaddingY = 200;
   Int32 chartW = 320;
   Int32 chartH = 200;
   Int32 chartXCount = 0;
   Int32 chartYCount = 1;
   Int32 marginTop = 0;
   Int32 marginLeft = 0;
   Int32 resultsControlVar = 0;
   Int32 numCharts = 0;
   Int32 rnStart = 14;
   chartXCount = 0;
   chartYCount = 0;
   chartPaddingX = 50;
  
   rowNum = y = 14;
   colNum = 2;
  
  
   String title = section.First().title.ToString();
   ExcelWorksheet ws = pkg.Workbook.Worksheets.Add(title);
  
   int idx = 0;
  
   foreach (var question in results.questions.Where(q =&gt; q.section_guid == section.Key))
   {
       var chart = ws.Drawings.AddChart(question.question.ToString(), OfficeOpenXml.Drawing.Chart.eChartType.ColumnClustered);
       chart.SetSize(chartW, chartH);
       chart.Title.Text = question.question.ToString();
       chart.Legend.Add();
  
       marginLeft = (chartW + chartPaddingX) * chartXCount;
  
       // SET CHART PLACEMENT
       if (numCharts == 0)
       {
           marginTop = 50;
       }
       else if ((numCharts &lt;= 3) &amp;&amp; (numCharts != 0))
       {
           marginTop = 50;
       }
       else if (numCharts &gt; 3)
       {
           marginTop = ((chartH + chartPaddingY) * chartYCount) + 50;
       }
       else
       {
           marginTop = (chartH + chartPaddingY) * chartYCount;
       }
  
       if (chartXCount &gt;= 3)
       {
           chart.SetPosition(marginTop, 50);
           chartYCount++;
           chartXCount = 0;
           resultsControlVar = 1;
       }
           else
       {
           chart.SetPosition(marginTop, marginLeft + 50);
       }
  
       chartXCount++;
       numCharts++;
  
       ...... Add results data and chart series ......
  
        if (resultsControlVar == 1)
        {
            rowNum = rnStart;
            rowNum = rowNum + 20;
            rnStart = rowNum;
            colNum = 2;
            resultsControlVar = 0;
        }
        else
        {
            rowNum = rnStart;
            colNum = colNum + 6;
        }
    } // close foreach
  </code></pre>