title: Create bar chart in PHPExcel
body: <p>I am trying to create a bar chart in PHPExcel following the <a href="https://github.com/PHPOffice/PHPExcel/blob/1.8/Examples/33chartcreate-bar.php" rel="nofollow noreferrer">33-chartcreate-composite-chart.php</a> example.</p>
  
  <p>The code before calling <code>createExcelGraph()</code> creates the worksheet shown at the screenshot. The produced chart is added to the worksheet but the resulting file contains no graph or better no graph is shown. No errors are reported by Excel during file load.</p>
  
  <p><a href="https://i.stack.imgur.com/5CrlE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5CrlE.png" alt="enter image description here"></a></p>
  
  <pre><code>private function createExcelStats($occurrences, $labels, $ticks, $graphLabel) {
    require_once __SITE_PATH . 'libraries\Excel\PHPExcel.php';
  
    $objPHPExcel = new PHPExcel();
    $objPHPExcel-&gt;getProperties()-&gt;setCreator("eOccurrence"); 
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
  
    $objSheet = $objPHPExcel-&gt;getActiveSheet();
    $objSheet-&gt;setTitle($graphLabel);
  
    /* writing x-axis */
    for ($i=1;$i&lt;=count($ticks);$i++) {
      $objSheet-&gt;setCellValueByColumnAndRow($i, 1, $ticks[$i-1]);
    }
    /* writing y-axis */
    for ($i=1;$i&lt;=count($labels);$i++) {
      $objSheet-&gt;setCellValueByColumnAndRow(0, $i+1, $labels[$i-1]['label']);
    }
  
    /* writing content */
    for ($i=0;$i&lt;count($labels);$i++){
      for ($j=0;$j&lt;count($ticks);$j++){
        $objSheet-&gt;setCellValueByColumnAndRow($j+1, $i+2, $occurrences[$i][$j]);
      }    
    }
  
    $ch = $this-&gt;createExcelGraph(count($ticks), count($labels));
    $objSheet-&gt;addChart($ch);  
  
    $this-&gt;checkdir(__SITE_PATH . 'uploads' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR);
    removeoldfiles(__SITE_PATH . 'uploads' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR, 'xlsx');
    $filename =  $graphLabel . '.xlsx';
  
    $objWriter-&gt;save(__SITE_PATH . 'uploads' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .  $filename);
    return ['code' =&gt; '0', 'filename' =&gt; $filename];
  }
  
  /*----------------------------------------------------------------------------*/
  
  private function createExcelGraph($cols, $rows) {
  /* Κάνουμε την υπόθεση ότι το πάνω αριστερό κελί του πίνακα βρίσκεται στο B2 */  
  
  //  Set the Labels for each data series we want to plot
  //      Datatype
  //      Cell reference for data
  //      Format Code
  //      Number of datapoints in series
  //      Data values
  //      Data Marker
    $dataSeriesLabels = array();
    for ($i=1;$i&lt;=$rows;$i++) {    
      $dataSeriesLabels[] = new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$' . ($i+1), NULL, 1);
    }
  //  Set the X-Axis Labels
  //      Datatype
  //      Cell reference for data
  //      Format Code
  //      Number of datapoints in series
  //      Data values
  //      Data Marker
    $col = $this-&gt;columnLetter($cols+1);
    $xAxisTickValues = array(    
      new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1:$' . $col . '$1', NULL, $cols)
    );
  //  Set the Data values for each data series we want to plot
  //      Datatype
  //      Cell reference for data
  //      Format Code
  //      Number of datapoints in series
  //      Data values
  //      Data Marker
    $dataSeriesValues = array();
  //  for ($i=1;$i&lt;=$rows;$i++) {    
  //    $dataSeriesValues[] = new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$'. ($i+1) . ':$' . $col .'$' . ($i+1), NULL, $cols);
  //  }
    for ($i=1;$i&lt;=$cols;$i++) {
      $col = $this-&gt;columnLetter($i+1);
      $dataSeriesValues[] = new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$' . $col . '$2:$' . $col . '$' . ($rows+1), NULL, $rows);
    }        
  //  Build the dataseries
  $series = new PHPExcel_Chart_DataSeries(
      PHPExcel_Chart_DataSeries::TYPE_BARCHART,       // plotType
      PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED,  // plotGrouping
      range(0, count($dataSeriesValues)-1),           // plotOrder
      $dataSeriesLabels,                              // plotLabel
      $xAxisTickValues,                               // plotCategory
      $dataSeriesValues                               // plotValues
  );
  //  Set additional dataseries parameters
  //      Make it a horizontal bar rather than a vertical column graph
  $series-&gt;setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_BAR);
  
  //  Set the series in the plot area
  $plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series));
  //  Set the chart legend
  $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
  
  $title = new PHPExcel_Chart_Title('Test Bar Chart');
  $yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');
  
  
  //  Create the chart
  $chart = new PHPExcel_Chart(
      'chart1',       // name
      $title,         // title
      $legend,        // legend
      $plotArea,      // plotArea
      true,           // plotVisibleOnly
      0,              // displayBlanksAs
      NULL,           // xAxisLabel
      $yAxisLabel     // yAxisLabel
  );
  
  //  Set the position where the chart should appear in the worksheet
  $chart-&gt;setTopLeftPosition('A7');
  $chart-&gt;setBottomRightPosition('H5');
  
  //  Add the chart to the worksheet
  //$objWorksheet-&gt;addChart($chart);  
  return $chart;
  }
  </code></pre>