title: PHPExcel two separate chart in one sheet?
body: <p>I used the bellow code to generate chart using PHPExcel. But now i cant draw two chart that each of them should use from separate data source in one sheet, so any change or suggestion is welcome.</p>
  
  <pre><code>    $workbook-&gt;getProperties()
              -&gt;setCreator("TRAINING")
              -&gt;setLastModifiedBy("TRAINING")
              -&gt;setTitle("TRAINING")
              -&gt;setSubject("TRAINING")
              -&gt;setDescription("TRAINING")
              -&gt;setKeywords("TRAINING Document")
              -&gt;setCategory("TRAINING Document");
              $rotation = "";
      // Define variables for chart settings 
      $startRow_num = '3'; 
      $totalWhiteRows = 2; 
      $category_start = $startRow_num+1;
      // get the total number of rows that data source is write in plus one white row for A1 
      $total_rows = count($course_rep)+$totalWhiteRows;
      $start_ofChart = $total_rows+1;    
      for($sh = 0; $sh &lt;= 1; $sh++)
      {
  
          //$sheet = $sheet.''.$sh;              
          //$excel-&gt;setActiveSheetIndex(3);
  
          if($sh == 0)
          {   
              $sheet = $workbook-&gt;createSheet($sh);
              $sheet = $workbook-&gt;setActiveSheetIndex($sh);
              $workbook-&gt;getActiveSheet()-&gt;setTitle('worksheet1');
              $sheet_name = $sheet-&gt;getTitle();
          }
          elseif($sh == 1)
          {   //$sheet = $workbook-&gt;createSheet($sh);
              $sheet = $workbook-&gt;setActiveSheetIndex($sh);
              $workbook-&gt;getActiveSheet()-&gt;setTitle('worksheet2');
              $sheet_name = $sheet-&gt;getTitle();
          }
          //echo "&lt;pre/&gt;"; print_r($sheet_name); exit;
          $workbook-&gt;getActiveSheet()-&gt;getTabColor()-&gt;setRGB('CC000#'); 
          $styleHeadings = array(
                                  'borders' =&gt; array(
                                      'allborders' =&gt; array(
                                          'style' =&gt; PHPExcel_Style_Border::BORDER_THIN,
                                              'color' =&gt; array('argb' =&gt; '#DBDBB7'),
                                          ),
                                      ),
                                  'font' =&gt; array(
                                      'bold' =&gt; true,
                                      'size' =&gt; 20 
                                      ),
                                  'fill' =&gt; array(
                                      'type' =&gt; PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
                                      'startcolor' =&gt; array(
                                          'argb' =&gt; 'E9E9E9',
                                      ),
                                      'endcolor' =&gt; array(
                                          'argb' =&gt; 'E9E9E9',
                                      ),
                                  ),
                                  'alignment' =&gt; array(
                                  'horizontal' =&gt; PHPExcel_Style_Alignment::HORIZONTAL_CENTER
                                  ),   
                      );
          if($this-&gt;mng_auth-&gt;get_language()=='en')
          {
              $sheet-&gt;setRightToLeft(false); 
          }
          else
          {  
              $sheet-&gt;setRightToLeft(true); 
          }
          $sheet-&gt;getStyle('G1:O2')-&gt;applyFromArray($styleHeadings);
          if($sh == 0)
          {
              $sheet-&gt;setCellValue('G1','ÑÇæÑ æÑÓ åÇ Èå ÇÓÇÓ ÑÊÈå ÔÇÑÏ');
          }
          else
          {
              $sheet-&gt;setCellValue('G1','ÑÇæÑ æÑÓ åÇ Èå ÇÓÇÓ ãÍá æÙíÝå ÔÇÑÏ');
          }
          $sheet-&gt;getStyle('G1:O2')-&gt;getAlignment()-&gt;setWrapText(true);
          //$sheet-&gt;setCellValue('H11','ãÌãæÚ ÔÇÑÏÇä'); 
          $sheet-&gt;mergeCellsByColumnAndRow(6,1,14,2);
          if($sh == 0)
          {
              $sheet-&gt;fromArray(  
                 $course_rep,
                 NULL,
                 'A'.$startRow_num 
              );
          }
          else
          {
              $sheet-&gt;fromArray(  
                 $course_jobLocBasedrep,
                 NULL,
                 'A'.$startRow_num  
              );
  
          }
          $sheet-&gt;fromArray(  
                 $chart_total_stdOfCourse,
                 NULL,
                 'Q'.$startRow_num  
              );
          $labels = array(
            new PHPExcel_Chart_DataSeriesValues('String', $sheet_name.'!$B$'.$startRow_num, null, 1),
            new PHPExcel_Chart_DataSeriesValues('String', $sheet_name.'!$C$'.$startRow_num, null, 1), 
            new PHPExcel_Chart_DataSeriesValues('String', $sheet_name.'!$D$'.$startRow_num, null, 1), 
            new PHPExcel_Chart_DataSeriesValues('String', $sheet_name.'!$E$'.$startRow_num, null, 1), 
          );
  
          // find the end row number of data source because we write from A2 so A3 is the start of main data 
  
          $categories = array(
            new PHPExcel_Chart_DataSeriesValues('String', $sheet_name.'!$A$'.$category_start.':$A$'.$total_rows, null, 4),   
          );
          $values = array(
            new PHPExcel_Chart_DataSeriesValues('Number', $sheet_name.'!$B$'.$category_start.':$B$'.$total_rows, null, 4),
            new PHPExcel_Chart_DataSeriesValues('Number', $sheet_name.'!$C$'.$category_start.':$C$'.$total_rows, null, 4),  
            new PHPExcel_Chart_DataSeriesValues('Number', $sheet_name.'!$D$'.$category_start.':$D$'.$total_rows, null, 4),  
            new PHPExcel_Chart_DataSeriesValues('Number', $sheet_name.'!$E$'.$category_start.':$E$'.$total_rows, null, 4),  
          );     
          $series = new PHPExcel_Chart_DataSeries(
            PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D,     // plotType
            PHPExcel_Chart_DataSeries::GROUPING_STACKED,  // plotGrouping
            array(0,1,2,3),                                     // plotOrder
            $labels,                                        // plotLabel
            $categories,                                    // plotCategory
            $values                                         // plotValues
          );  
  
          $series-&gt;setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
  
          // Total student chart 
          $total_labels = array(
            new PHPExcel_Chart_DataSeriesValues('String', $sheet_name.'!$Q$'.$startRow_num, null, 1),
            new PHPExcel_Chart_DataSeriesValues('String', $sheet_name.'!$R$'.$startRow_num, null, 1), 
          );
  
          // find the end row number of data source because we write from A2 so A3 is the start of main data 
  
          $total_categories = array(
            new PHPExcel_Chart_DataSeriesValues('String', $sheet_name.'!$Q$'.$category_start.':$Q$'.$total_rows, null, 4),   
          );
          $total_values = array(
            new PHPExcel_Chart_DataSeriesValues('Number', $sheet_name.'!$R$'.$category_start.':$R$'.$total_rows, null, 4),  
          );     
          $total_series = new PHPExcel_Chart_DataSeries(
            PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D,     // plotType
            PHPExcel_Chart_DataSeries::GROUPING_STACKED,  // plotGrouping
            array(0,1),                                     // plotOrder
            $total_labels,                                        // plotLabel
            $total_categories,                                    // plotCategory
            $total_values                                         // plotValues
          );  
  
          $total_series-&gt;setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
          $layout1 = new PHPExcel_Chart_Layout();    // Create object of chart layout to set data label 
          $layout1-&gt;setShowVal(TRUE);                   
          $layout1-&gt;setManual3dAlign(true);
          $layout1-&gt;setXRotation(20);
          $layout1-&gt;setYRotation(20);
          $layout1-&gt;setPerspective(15);                                              
          $layout1-&gt;setRightAngleAxes(TRUE);                                              
          //$layout1-&gt;setShowPercent(TRUE);
          //$layout1-&gt;setShowCatName(TRUE);
          //$layout1-&gt;setShowSerName(TRUE);
          //$layout1-&gt;setShowBubbleSize(TRUE);
          //$layout1-&gt;setShowLeaderLines(TRUE);
          //$layout1-&gt;setShowLegendKey(TRUE);
          //$image = base_url().'image/app_req.jpeg';
          //$header1 = new PHPExcel_Worksheet();
  
          //$header1-&gt;setHeaderFooter(PHPExcel_Worksheet_HeaderFooter::addImage($image,'A12'));
          $plotarea = new PHPExcel_Chart_PlotArea($layout1, array($series,$total_series));
          $title    = new PHPExcel_Chart_Title($this-&gt;lang-&gt;line('co_report'), null);  
          //$title = new PHPExcel_Chart_Title(new PHPExcel_RichText(new PHPExcel_Cell('A','1','Ttile Chart',PHPExcel_Cell_DataType::TYPE_STRING,$sheet)));
          $legend   = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, null, false);
          $xTitle   = new PHPExcel_Chart_Title($this-&gt;lang-&gt;line('course_names'));
          $yTitle   = new PHPExcel_Chart_Title($this-&gt;lang-&gt;line('no_std'));
          $chart    = new PHPExcel_Chart(
            'chart1',                                       // name
            $title,                                         // title
            $legend,                                        // legend 
            $plotarea,                                      // plotArea
            true,                                           // plotVisibleOnly
            0,                                              // displayBlanksAs
            $xTitle,                                        // xAxisLabel
            $yTitle                                         // yAxisLabel
          );                      
          $chart-&gt;setTopLeftPosition('B'.$start_ofChart);
          $chart-&gt;setBottomRightPosition('J25');
          //echo "&lt;pre/&gt;";print_r($chart); exit;  
          //echo "&lt;pre/&gt;"; print_r($workbook); exit; 
          $sheet-&gt;addChart($chart); 
      }   
      header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
      header('Content-Disposition: attachment;filename="training report.xlsx"');
      header('Cache-Control: max-age=0'); 
      $writer = PHPExcel_IOFactory::createWriter($workbook, 'Excel2007');
      $writer-&gt;setIncludeCharts(TRUE);
      ob_start();
      ob_end_clean(); 
      $writer-&gt;save('php://output');
  </code></pre>
  
  <p>I should draw two chart in each sheet in a manner that each chart should use from itself data source but the above code cant draw the chart just it write the data source value in the specified column row inside sheet. But if i draw one chart in a sheet the above code is run true.</p>