code: public function addChart(Chart $pChart, $iChartIndex = null)
      {
          $pChart->setWorksheet($this);
          if ($iChartIndex === null) {
              $this->chartCollection[] = $pChart;
          } else {
              // Insert the chart at the requested index
              array_splice($this->chartCollection, $iChartIndex, 0, [$pChart]);
          }
  
          return $pChart;
      }
docs: Add chart.
  
  @param Chart $pChart
  @param null|int $iChartIndex Index where chart should go (0,1,..., or null for last)
  
  @return Chart