I am trying to combine two examples. eg1 and eg2 runs fine independently.
I would like to create a chart from php but allows me to save it where I want. But when I try to open always tells me it's corrupt or extension is not correct.
I have looked some answers to similar questions and have not been able to find appropriate solution.
What am I missing here?
Well, finally i did it.
Now the problem is, i can't rename the worksheet where i save the graph.
If i do that, Excel can't open the file.
The code:
<?php
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
/** 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),
)
);
$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),
);
// Build the dataseries
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($dataSeriesValues)-1), // plotOrder
$dataseriesLabels, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues // plotValues
);
// Set additional dataseries parameters
// Make it a vertical column rather than a horizontal bar graph
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
// 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 Column 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);
$objPHPExcel->getActiveSheet()->setTitle('Probando');
// Save Excel 2007 file
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
exit;
The line "$objPHPExcel->getActiveSheet()->setTitle('Probando');" is the problem, some idea?
PS: Sorry for my bad english.
#koky
Rename the sheet first, and then create the table and graph, like so:
<?php
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
/** PHPExcel */
require_once dirname(__FILE__) . '/Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objWorksheet = $objPHPExcel->getActiveSheet();
$objPHPExcel->getActiveSheet()->setTitle('Probando');
$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),
)
);
$dataseriesLabels = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Probando!$B$1', NULL, 1), // 2010
new PHPExcel_Chart_DataSeriesValues('String', 'Probando!$C$1', NULL, 1), // 2011
new PHPExcel_Chart_DataSeriesValues('String', 'Probando!$D$1', NULL, 1), // 2012
);
$xAxisTickValues = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Probando!$A$2:$A$5', NULL, 4), // Q1 to Q4
);
$dataSeriesValues = array(
new PHPExcel_Chart_DataSeriesValues('Number', 'Probando!$B$2:$B$5', NULL, 4),
new PHPExcel_Chart_DataSeriesValues('Number', 'Probando!$C$2:$C$5', NULL, 4),
new PHPExcel_Chart_DataSeriesValues('Number', 'Probando!$D$2:$D$5', NULL, 4),
);
// Build the dataseries
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($dataSeriesValues)-1), // plotOrder
$dataseriesLabels, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues // plotValues
);
// Set additional dataseries parameters
// Make it a vertical column rather than a horizontal bar graph
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
// 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 Column 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
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
exit;
?>
Related
GitHub automatically generates meta tag image for each repository with dynamic content if user doesn't provide any thumbnail image.
eg:
<meta property="og:image" content="https://opengraph.githubassets.com/6fa26478850d4904c9e8567353350c87f35c71f7232cce8eec1d44e3ba1ca9a3/e-labInnovations/qr-code-speech">
This is the meta image for one of my repository https://github.com/e-labInnovations/qr-code-speech
I want impliment this feature on my wordpress. Generate dynamic png image contain post title, date, author name, and author avatar image.
Is it possible in WordPress?
If yes, then how?
function.php
<?php
add_action( 'init', function() {
add_rewrite_rule( 'ashad-thumbnail/([a-z0-9-]+)[/]?$', 'index.php?ashad-thumbnail=$matches[1]', 'top' );
} );
add_filter( 'query_vars', function( $query_vars ) {
$query_vars[] = 'ashad-thumbnail';
return $query_vars;
} );
add_action( 'template_include', function( $template ) {
if ( get_query_var( 'ashad-thumbnail' ) == false || get_query_var( 'ashad-thumbnail' ) == '' ) {
return $template;
}
return get_template_directory() . '/templates/ashad-thumbnail.php';
} );
?>
ashad-thumbnail.php
<?php
//setting content type as png
header ('Content-Type: image/png');
//create image object
$img = imagecreatetruecolor(1200, 600)
or die('Cannot Initialize new GD image stream');
//Colors
$background_color = imagecolorallocate($img, 255, 255, 255);
$color_primary = imagecolorallocate($img, 50, 50, 50);
$color_secondary = imagecolorallocate($img, 100, 100, 100);
$post_id = get_query_var('ashad-thumbnail');
//setting background color
imagefill($img, 0, 0, $background_color);
//getting author name using author_id
$author_id = get_post_field ('post_author', $post_id);
$display_name = get_the_author_meta( 'display_name' , $author_id );
// $text = "Post Id: " . get_query_var( 'ashad-thumbnail' ) . get_comments_number($post_id);
// imagestring($img, 5, 10, 10, $text, $color_primary);
//loading ttf fonts
$fontSemiBold = get_stylesheet_directory() . '/assets/fonts/TitilliumWeb-SemiBold.ttf';
$fontRegular = get_stylesheet_directory() . '/assets/fonts/TitilliumWeb-Regular.ttf';
//creating icon image objects
$icon_calendar = imagecreatefrompng(get_stylesheet_directory() . '/assets/img/icon_calendar.png');
$icon_comments = imagecreatefrompng(get_stylesheet_directory() . '/assets/img/icon_comments.png');
//creating site icon(favicon) image object
$site_icon = imagecreatefrompng(get_site_icon_url(200));
//getting title
$title = get_the_title(get_query_var( 'ashad-thumbnail' )) ? get_the_title($post_id) : 'Error';
if(strlen($title) > 21) {
$titleArray = explode("\n", wordwrap( $title, 26));
$titleL1 = $titleArray[0];
if($titleArray[1]) {
if($titleArray[2]) {
$titleL2 = $titleArray[1] . '...';
} else {
$titleL2 = $titleArray[1];
}
} else {
$titleL2 = flase;
}
} else {
$titleL1 = $title;
}
$fsize = 48;
//showing title line 1 and 2
imagettftext($img, $fsize, 0, 80, 140, $color_primary, $fontSemiBold, $titleL1);
if($titleL2) {
imagettftext($img, $fsize, 0, 80, 210, $color_primary, $fontSemiBold, $titleL2);
}
//showing author name
if($display_name) {
imagettftext($img, 26, 0, 80, 295, $color_secondary, $fontRegular, 'By ' . $display_name);
}
//showing site_icon
imagecopyresized($img, $site_icon, 922, 80, 0, 0, 200, 200, 200, 200);
//showing date icon and date
imagecopyresized($img, $icon_calendar, 80, 450, 0, 0, 32, 32, 16, 16);
imagettftext($img, 26, 0, 130, 478, $color_primary, $fontRegular, get_the_date('F j, Y', $post_id));
//showing a circle and post type label
imagearc($img, 550, 465, 32, 32, 0, 360, $color_primary);
imagettftext($img, 26, 0, 580, 478, $color_primary, $fontRegular, get_post_type_object(get_post_type($post_id))->labels->singular_name);
//showing comments icon and count
imagecopyresized($img, $icon_comments, 900, 450, 0, 0, 32, 32, 16, 16);
imagettftext($img, 26, 0, 950, 478, $color_primary, $fontRegular, get_comments_number($post_id));
imagepng($img);
imagedestroy($img);
?>
For getting this thumbnail image use example.com/ashad-thumbnail/:post_id. Replace post_id with real post id
Example image
Note
I used two google fonts as ttf format.
I want to use phpexcel to draw a radar chart, but when I open the generated file with Microsoft Excel 2010, the chart's main axis is missing(like below image, the first is wrong, the second is correct).
The wrong chart draw by phpexcel
The correct chart draw by Excel 2010
Then I read phpexcel's examples '33chartcreate-radar.php', but it has the same problem.
How do I make the main axis show?
$excel = new PHPExcel();
$sheet = $excel->getActiveSheet();
$sheet->setTitle('sheet');
$data = [
['Direction', 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'],
['Frequency', 10, 20, 5, 10, 15, 30, 5, 5]
];
$sheet->fromArray($data, null, 'A1');
$dataseriesLabels = array(new PHPExcel_Chart_DataSeriesValues('String',
'sheet!$A$2', NULL, 1));
$xAxisTickValues = array(new PHPExcel_Chart_DataSeriesValues('String',
'sheet!$B$1:$I$1', NULL, 8));
$dataSeriesValues = array(new PHPExcel_Chart_DataSeriesValues('String',
'sheet!$B$2:$I$2', NULL, 8));
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_RADARCHART,
null,
range(0, count($dataSeriesValues)-1),
$dataseriesLabels,
$xAxisTickValues,
$dataSeriesValues,
null,
null,
PHPExcel_Chart_DataSeries::STYLE_MARKER
);
$plotarea = new PHPExcel_Chart_PlotArea(null, array($series));
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_TOPRIGHT,
NULL, false);
$title = new PHPExcel_Chart_Title('Wind Rose Diagram');
$chart = new PHPExcel_Chart(
'chart1',
$title,
$legend,
$plotarea,
true,
0,
null,
null
);
$chart->setTopLeftPosition('A7');
$chart->setBottomRightPosition('I32');
$sheet->addChart($chart);
$ExcelWrite = PHPExcel_IOFactory::createWriter($excel, "Excel2007");
$ExcelWrite->setIncludeCharts(true);
$ExcelWrite->save('D:\TestRadarChart.xlsx');
If Excel vba is OK, I could display it.
ActiveChart.Axes(xlCategory).hasMajorGridlines=true
Select the target chart on excel.
Press Alt+F11 on excel, then VBE opens.
Press Ctrl+G on VBE, then immediate window opens.
Paste the above code.
Place the cursor on the line of the code and press the enter key.
I made the file with PHPExcel and edit it with excel 2010.
I do not know about side effect, but it may be possible to fix it.
I confirmed with PHPExcel 1.8.0.
source:
Lib/PHPExcel/Classes/PHPExcel/Writer/Excel2007/Chart.php(450)
before:
$objWriter->startElement('c:axPos');
$objWriter->writeAttribute('val', "b");
$objWriter->endElement();
after:
$objWriter->startElement('c:axPos');
$objWriter->writeAttribute('val', "b");
$objWriter->endElement();
$objWriter->startElement('c:majorGridlines'); //added
$objWriter->endElement(); //added
Today i'm working with phpexcel to generate some bar chart in my files.
Nevertheless, i dont get expected labels on my legend except the first :
Bad labels on legend
I dont get it because i put the right range in my dataseries labels array. Only the first label is right but others are by default "Series2, Serie3, ..."
This is my code :
// Each worksheet
foreach($tab_calcul as $calcul => $bool){
$tab_length_lig = ${"worksheet_$calcul"}->getHighestRow();
$tab_length_col = PHPExcel_Cell::columnIndexFromString(${"worksheet_$calcul"}->getHighestColumn())-1;
///////////////////////////////////////////////////////////////////////
//////////////// DATASERIES BY SHOP ////////////////////////
///////////////////////////////////////////////////////////////////////
// Shop labels
$dataseriesLabels = array(
new PHPExcel_Chart_DataSeriesValues('String', '$calcul!$A$4:$A$'.($tab_length_lig-1), NULL, $nb_enseigne)
);
// Dates
$xAxisTickValues = array(
new PHPExcel_Chart_DataSeriesValues('String', '$calcul!$C$3:$'.ch2al($tab_length_col).'$3', NULL, $nb_synthese)
);
// Values
$dataSeriesValues = array();
$cpt = 3;
for($i = 0; $i < count($tab_enseigne); $i++) {
$cpt++;
array_push($dataSeriesValues, new PHPExcel_Chart_DataSeriesValues('Number', '$calcul!$C$'.$cpt.':$'.ch2al($tab_length_col).'$'.$cpt, NULL, $nb_synthese));
}
// Build the dataseries
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD , // plotGrouping
range(0, count($dataSeriesValues)-1), // plotOrder
$dataseriesLabels, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues // plotValues
);
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COLUMN);
///////////////////////////////////////////////////////////////////////
/////////////// DATASERIES ALL SHOPS /////////////////////
///////////////////////////////////////////////////////////////////////
// Label all shops
$dataseriesLabels2 = array(
new PHPExcel_Chart_DataSeriesValues('String', '$calcul!$A$'.($tab_length_lig), NULL, 1)
);
// Values
$dataSeriesValues2 = array(
new PHPExcel_Chart_DataSeriesValues('Number', '$calcul!$C$'.$tab_length_lig.':$'.ch2al($tab_length_col).'$'.$tab_length_lig, NULL, $nb_synthese)
);
// Build the dataseries
$series2 = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_LINECHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD , // plotGrouping
range(0, count($dataSeriesValues2)-1), // plotOrder
$dataseriesLabels2, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues2 // plotValues
);
/////////////////////////////////////////////////////////////////////////
// Set the series in the plot area
$plotarea = new PHPExcel_Chart_PlotArea(NULL, array($series, $series2));
// Set the chart legend
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
$title = new PHPExcel_Chart_Title('Graphe '.$calcul." : ".utf8_encode($tab_data[$rmookid_periode]["marque"]." - ".$tab_data[$rmookid_periode]["modele"]." - ".$tab_data[$rmookid_periode]["ean"]));
// Create the chart
$chart = new PHPExcel_Chart(
'chart1', // name
$title, // title
$legend, // legend
$plotarea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
NULL, // xAxisLabel
NULL // yAxisLabel
);
// Set the position where the chart should appear in the worksheet
$chart->setTopLeftPosition('A17');
$chart->setBottomRightPosition('K30');
// Add the chart to the worksheet
${"worksheet_$calcul"}->addChart($chart);
}
Thank you in advance
I fixed it. It was a huge mistake to put $calcul in simple quote :
'$calcul!$A$'.($tab_length_lig)
Should be :
$calcul.'!$A$'.($tab_length_lig)
Is there a way to setup our graph so it will look like this .. http://www.epicstan.com/graf.jpg ?
We can't find out how to get rid of the number around our graph.
Here is the file that is generated http://www.epicstan.com/export.xlsx and on sheet 2 we need to change that graph look.
Here is the code ..
<?php
/* part of generater code */
/* charts */
$dataSeriesValues = array(
new \PHPExcel_Chart_DataSeriesValues('Number', 'sheet2!$I$'.(($i*5)+3).':$I$'.(($i*5)+5), NULL, 6),
);
// Build the dataseries
$series = new \PHPExcel_Chart_DataSeries(
\PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D, // plotType
NULL,
range(0, count($dataSeriesValues)-1),
NULL,
NULL,
$dataSeriesValues
);
$series->setPlotDirection(\PHPExcel_Chart_DataSeries::DIRECTION_BAR);
$layout = new \PHPExcel_Chart_Layout();
$layout->setManual3dAlign(true);
$layout->setXRotation(10);
$layout->setYRotation(20);
$layout->setRightAngleAxes(1);
$layout->setShowVal(true);
$plotarea = new \PHPExcel_Chart_PlotArea($layout, array($series));
$chart = new \PHPExcel_Chart(
'chart1',
NULL,
NULL,
$plotarea,
true,
0,
NULL,
NULL
);
$chart->setTopLeftPosition('I'.(($i*5)+2));
$chart->setBottomRightPosition('J'.(($i*5)+8));
$excel->getActiveSheet()->addChart($chart);
$excel->setActiveSheetIndex(0);
$objWriter = new \PHPExcel_Writer_Excel2007($excel);
$objWriter->setIncludeCharts(TRUE);
$file = DOWNLOAD_DIR . 'export.xlsx';
$objWriter->save($file);
Thank you.
Peter
Change your arguments for the dataseries constructor to set an empty series of string plotCategories:
// Build the dataseries
$series = new \PHPExcel_Chart_DataSeries(
\PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D, // plotType
NULL,
range(0, count($dataSeriesValues)-1),
NULL,
new \PHPExcel_Chart_DataSeriesValues(
'String',
NULL,
NULL,
count($dataSeriesValues)
),
$dataSeriesValues
);
Is it possible to create a line and bar graph using PHPExcel? Like this one below.
If not is it possible to make a graph background transparent so I can merge two graphs together?
I had to make a minor tweak to the PHPExcel code to get it working correctly, just pushed it to github; together with 33chartcreate-composite-chart.php in /Examples.
$objPHPExcel = new PHPExcel();
$objWorksheet = $objPHPExcel->getActiveSheet();
$objWorksheet->fromArray(
array(
array('', 'Rainfall (mm)', 'Temperature (°F)', 'Humidity (%)'),
array('Jan', 78, 52, 61),
array('Feb', 64, 54, 62),
array('Mar', 62, 57, 63),
array('Apr', 21, 62, 59),
array('May', 11, 75, 60),
array('Jun', 1, 75, 57),
array('Jul', 1, 79, 56),
array('Aug', 1, 79, 59),
array('Sep', 10, 75, 60),
array('Oct', 40, 68, 63),
array('Nov', 69, 62, 64),
array('Dec', 89, 57, 66),
)
);
// 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
$dataseriesLabels1 = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // Temperature
);
$dataseriesLabels2 = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // Rainfall
);
$dataseriesLabels3 = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // Humidity
);
// 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$13', NULL, 12), // Jan to Dec
);
// 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
$dataSeriesValues1 = array(
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$13', NULL, 12),
);
// Build the dataseries
$series1 = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping
range(0, count($dataSeriesValues1)-1), // plotOrder
$dataseriesLabels1, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues1 // plotValues
);
// Set additional dataseries parameters
// Make it a vertical column rather than a horizontal bar graph
$series1->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
// 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
$dataSeriesValues2 = array(
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', NULL, 12),
);
// Build the dataseries
$series2 = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_LINECHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($dataSeriesValues2)-1), // plotOrder
$dataseriesLabels2, // plotLabel
NULL, // plotCategory
$dataSeriesValues2 // plotValues
);
// 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
$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, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($dataSeriesValues2)-1), // plotOrder
$dataseriesLabels3, // plotLabel
NULL, // plotCategory
$dataSeriesValues3 // plotValues
);
// 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', // name
$title, // title
$legend, // legend
$plotarea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
NULL, // xAxisLabel
NULL // yAxisLabel
);
// 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);