You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.
I am trying to create for the first time a PHPExcel Chart, a stacked bar, using example\33chartcreate-bar.php and adjusting to my needs. I will admit though, that I am adjusting blindly because I have not found any documentation on charts. So my question is 2-part:
Does anyone know of any documentation on PHPExcel Charts (their PDFs do not mention anything on this)?
Below I am pasting the working example, my code, the var dump and the error I get. The error I get refers to the PHPEXcel file, but this usualy means that I am sending incorrect information, but I dont have a clue of what information?
Working Example:
{
');
date_default_timezone_set('Europe/London');
/**
- PHPExcel
*
- Copyright (C) 2006 - 2014 PHPExcel
*
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
*
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
*
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
- @category PHPExcel
- @Package PHPExcel
- @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
- @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
- @Version 1.8.0, 2014-03-02
*/
/*\* PHPExcel */
require_once dirname(**FILE**) . '/../Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objWorksheet = $objPHPExcel->getActiveSheet();
$objWorksheet->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),
)
);
// 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(
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
);
// Set the X-Axis Labels
// Datatype
// Cell reference for data
// Format Code
// Number of datapoints in series
// Data values
// Data Marker
$xAxisTickValues = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4
);
// 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(
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_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->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->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;
echo 'File has been created in ' , getcwd() , EOL;
}
My code:
{
//I have already populated my cells and are showing correctly
private static function draw_graph($excel_last_row, &$excel_obj){
```
$excel_last_row -= 2;
//Do Trip Labels
$dataseriesLabels = array(
new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$C$4', NULL, 1), // Trip A
new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$D$4', NULL, 1), // Trip B
new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$E$4', NULL, 1), // Trip C
new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$F$4', NULL, 1), // Trip D
new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$G$4', NULL, 1), // Trip E
new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$H$4', NULL, 1), // Trip F
new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$I$4', NULL, 1), // Trip OUTSOURCED
);
//X-Axis Labels(Dates)
$x_labels = self::get_graph_col_range('B', $excel_last_row);
$xAxisTickValues = array(
new PHPExcel_Chart_DataSeriesValues('String', $x_labels, NULL, 1), // Dates
);
//plot actual values
$values_a = self::get_graph_col_range('C', $excel_last_row);
$values_b = self::get_graph_col_range('D', $excel_last_row);
$values_c = self::get_graph_col_range('E', $excel_last_row);
$values_d = self::get_graph_col_range('F', $excel_last_row);
$values_e = self::get_graph_col_range('G', $excel_last_row);
$values_f = self::get_graph_col_range('H', $excel_last_row);
$values_outsourced = self::get_graph_col_range('I', $excel_last_row);
$dataSeriesValues = array(
new PHPExcel_Chart_DataSeriesValues('String', $values_a, NULL, 1),
new PHPExcel_Chart_DataSeriesValues('String', $values_b, NULL, 1),
new PHPExcel_Chart_DataSeriesValues('String', $values_c, NULL, 1),
new PHPExcel_Chart_DataSeriesValues('String', $values_d, NULL, 1),
new PHPExcel_Chart_DataSeriesValues('String', $values_e, NULL, 1),
new PHPExcel_Chart_DataSeriesValues('String', $values_f, NULL, 1),
new PHPExcel_Chart_DataSeriesValues('String', $values_outsourced, NULL, 1),
);
//Build data series
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_STOCKCHART,
PHPExcel_Chart_DataSeries::GROUPING_STACKED,
range(0, count($dataSeriesValues)-1),
$dataseriesLabels,
$xAxisTickValues
);
//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_BOTTOM, NULL, false);
$title = new PHPExcel_Chart_Title('');
$yAxisLabel = new PHPExcel_Chart_Title('');
//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
$top_row = $excel_last_row + 4;
$bottom_row = $top_row + 24;
$chart->setTopLeftPosition('A' . $top_row);
$chart->setBottomRightPosition('M' . $bottom_row);
echo '
Hi,
I am trying to create for the first time a PHPExcel Chart, a stacked bar, using example\33chartcreate-bar.php and adjusting to my needs. I will admit though, that I am adjusting blindly because I have not found any documentation on charts. So my question is 2-part:
Working Example:
'); date_default_timezone_set('Europe/London'); /** - PHPExcel * - Copyright (C) 2006 - 2014 PHPExcel * - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. * - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. * - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - @category PHPExcel - @Package PHPExcel - @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) - @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL - @Version 1.8.0, 2014-03-02 */ /*\* PHPExcel */ require_once dirname(**FILE**) . '/../Classes/PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objWorksheet = $objPHPExcel->getActiveSheet(); $objWorksheet->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), ) ); // 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( 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 ); // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues = array( new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4 ); // 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( 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_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->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->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; echo 'File has been created in ' , getcwd() , EOL; } My code: { //I have already populated my cells and are showing correctly private static function draw_graph($excel_last_row, &$excel_obj){ ``` $excel_last_row -= 2; //Do Trip Labels $dataseriesLabels = array( new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$C$4', NULL, 1), // Trip A new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$D$4', NULL, 1), // Trip B new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$E$4', NULL, 1), // Trip C new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$F$4', NULL, 1), // Trip D new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$G$4', NULL, 1), // Trip E new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$H$4', NULL, 1), // Trip F new PHPExcel_Chart_DataSeriesValues('String', '\'Daily Passenger Totals\'!$I$4', NULL, 1), // Trip OUTSOURCED ); //X-Axis Labels(Dates) $x_labels = self::get_graph_col_range('B', $excel_last_row); $xAxisTickValues = array( new PHPExcel_Chart_DataSeriesValues('String', $x_labels, NULL, 1), // Dates ); //plot actual values $values_a = self::get_graph_col_range('C', $excel_last_row); $values_b = self::get_graph_col_range('D', $excel_last_row); $values_c = self::get_graph_col_range('E', $excel_last_row); $values_d = self::get_graph_col_range('F', $excel_last_row); $values_e = self::get_graph_col_range('G', $excel_last_row); $values_f = self::get_graph_col_range('H', $excel_last_row); $values_outsourced = self::get_graph_col_range('I', $excel_last_row); $dataSeriesValues = array( new PHPExcel_Chart_DataSeriesValues('String', $values_a, NULL, 1), new PHPExcel_Chart_DataSeriesValues('String', $values_b, NULL, 1), new PHPExcel_Chart_DataSeriesValues('String', $values_c, NULL, 1), new PHPExcel_Chart_DataSeriesValues('String', $values_d, NULL, 1), new PHPExcel_Chart_DataSeriesValues('String', $values_e, NULL, 1), new PHPExcel_Chart_DataSeriesValues('String', $values_f, NULL, 1), new PHPExcel_Chart_DataSeriesValues('String', $values_outsourced, NULL, 1), ); //Build data series $series = new PHPExcel_Chart_DataSeries( PHPExcel_Chart_DataSeries::TYPE_STOCKCHART, PHPExcel_Chart_DataSeries::GROUPING_STACKED, range(0, count($dataSeriesValues)-1), $dataseriesLabels, $xAxisTickValues ); //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_BOTTOM, NULL, false); $title = new PHPExcel_Chart_Title(''); $yAxisLabel = new PHPExcel_Chart_Title(''); //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 $top_row = $excel_last_row + 4; $bottom_row = $top_row + 24; $chart->setTopLeftPosition('A' . $top_row); $chart->setBottomRightPosition('M' . $bottom_row); echo '{
The text was updated successfully, but these errors were encountered: