// Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $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)); // Build the dataseries $series = new \PHPExcel\Chart\DataSeries(\PHPExcel\Chart\DataSeries::TYPE_SCATTERCHART, NULL, range(0, count($dataSeriesValues) - 1), $dataSeriesLabels, $xAxisTickValues, $dataSeriesValues, NULL, \PHPExcel\Chart\DataSeries::STYLE_LINEMARKER); // 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_TOPRIGHT, NULL, false); $title = new \PHPExcel\Chart\Title('Test Scatter Chart'); $yAxisLabel = new \PHPExcel\Chart\Title('Value ($k)'); // Create the chart $chart = new \PHPExcel\Chart('chart1', $title, $legend, $plotArea, true, 0, NULL, $yAxisLabel); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); // Add the chart to the worksheet $objWorksheet->addChart($chart); // Save Excel 2007 file echo date('H:i:s'), " Write to Excel2007 format", EOL; $objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->setIncludeCharts(TRUE); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); echo date('H:i:s'), " File written to ", str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)), EOL; // Echo memory peak usage echo date('H:i:s'), " Peak memory usage: ", memory_get_peak_usage(true) / 1024 / 1024, " MB", EOL; // Echo done echo date('H:i:s'), " Done writing file", EOL;
// Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues2 = array(new \PHPExcel\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4)); // Build the dataseries $series2 = new \PHPExcel\Chart\DataSeries(\PHPExcel\Chart\DataSeries::TYPE_DONUTCHART, NULL, range(0, count($dataSeriesValues2) - 1), $dataSeriesLabels2, $xAxisTickValues2, $dataSeriesValues2); // Set up a layout object for the Pie chart $layout2 = new \PHPExcel\Chart\Layout(); $layout2->setShowVal(TRUE); $layout2->setShowCatName(TRUE); // Set the series in the plot area $plotArea2 = new \PHPExcel\Chart\PlotArea($layout2, array($series2)); $title2 = new \PHPExcel\Chart\Title('Test Donut Chart'); // Create the chart $chart2 = new \PHPExcel\Chart('chart2', $title2, NULL, $plotArea2, true, 0, NULL, NULL); // Set the position where the chart should appear in the worksheet $chart2->setTopLeftPosition('I7'); $chart2->setBottomRightPosition('P20'); // Add the chart to the worksheet $objWorksheet->addChart($chart2); // Save Excel 2007 file echo date('H:i:s'), " Write to Excel2007 format", EOL; $objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->setIncludeCharts(TRUE); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); echo date('H:i:s'), " File written to ", str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)), EOL; // Echo memory peak usage echo date('H:i:s'), " Peak memory usage: ", memory_get_peak_usage(true) / 1024 / 1024, " MB", EOL; // Echo done echo date('H:i:s'), " Done writing file", EOL;
// Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues3 = array(new \PHPExcel\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', NULL, 12)); // Build the dataseries $series3 = new \PHPExcel\Chart\DataSeries(\PHPExcel\Chart\DataSeries::TYPE_AREACHART, \PHPExcel\Chart\DataSeries::GROUPING_STANDARD, range(0, count($dataSeriesValues2) - 1), $dataSeriesLabels3, NULL, $dataSeriesValues3); // Set the series in the plot area $plotArea = new \PHPExcel\Chart\PlotArea(NULL, array($series1, $series2, $series3)); // Set the chart legend $legend = new \PHPExcel\Chart\Legend(\PHPExcel\Chart\Legend::POSITION_RIGHT, NULL, false); $title = new \PHPExcel\Chart\Title('Average Weather Chart for Crete'); // Create the chart $chart = new \PHPExcel\Chart('chart1', $title, $legend, $plotArea, true, 0, NULL, NULL); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('F2'); $chart->setBottomRightPosition('O16'); // Add the chart to the worksheet $objWorksheet->addChart($chart); // Save Excel 2007 file echo date('H:i:s'), " Write to Excel2007 format", EOL; $objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->setIncludeCharts(TRUE); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); echo date('H:i:s'), " File written to ", str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)), EOL; // Echo memory peak usage echo date('H:i:s'), " Peak memory usage: ", memory_get_peak_usage(true) / 1024 / 1024, " MB", EOL; // Echo done echo date('H:i:s'), " Done writing file", EOL;