3

Laravel-excel パッケージでグラフを作成しようとしていますが、ファイルを作成してエクスポートするとグラフが表示されません。私はlaravel5.1を使用しています。excel.php ファイルにはプロパティ 'includeCharts' => true があります

    public function getChart(){
      $excel=  Excel::create('Users by Country-BetonLove',   function($excel)  {
       $excel->setTitle('Users by Country');
       $excel->setCompany('BetonLove');
       $excel->sheet('First sheet', function($sheet) {
       $sheet->fromArray(
        array(
            array('',   2010,   2011,   2012),
            array('Q1',   12,   15,     21),
            array('Q2',   56,   73,     86),
            array('Q3',   52,   61,     69),
            array('Q4',   30,   32,     0),
        )
      );
      $dataSeriesLabels = array(
        new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1),   //  2010
        new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1),   //  2011
        new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1),   //  2012
      );
      $xAxisTickValues = array(
        new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4),  //  Q1 to Q4
      );

      $dataSeriesValues = array(
        new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4),
        new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
        new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4),
      );

      $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
      );
      $series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_BAR);

      $plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series));
      $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->setTopLeftPosition('A7');
      $chart->setBottomRightPosition('H20');

      //    Add the chart to the worksheet
      $sheet->addChart($chart);
    });
  });
  $excel->export();
}
4

1 に答える 1