The library in question is PHPExcel 1.7.7
I've used sample code found in a thread at codeplex to create charts with PHPExcel. However, the sample code presented in the forums only deal with two columns of data, and I'm looking to expand the number of columns that are displayed in the chart. The third set of data (column D and beyond) are not being displayed no matter what I try to do with it.
There isn't a problem with the labels/categories strings - so there's no collision with any reserved names (even though they're strings), and I returned the plotValues to see if anything got lost, and I still see that the defined columns are shown in there, but can't figure out why the third column is not shown in the chart.
$excel->getActiveSheet()->fromArray(array(
$header ,
array('Central', 12, 15 , 12 ),
array('Northeast', 56, 73 , 10 ),
array('Southeast', 52, 61 , 33 ),
array('Western', 30, 32 , 55 ),
));
$labels = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Summary!$B$1', null, 1),
new PHPExcel_Chart_DataSeriesValues('String', 'Summary!$C$1', null, 1),
new PHPExcel_Chart_DataSeriesValues('String', 'Summary!$D$1', null, 1),
);
$categories = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Summary!$A$2:$A$5', null, 4),
);
// this is where the problem arises - the third DataSeriesValues is not being displayed
$values = array(
new PHPExcel_Chart_DataSeriesValues('Number', 'Summary!$B$2:$B$5', null, 4),
new PHPExcel_Chart_DataSeriesValues('Number', 'Summary!$C$2:$C$5', null, 4),
new PHPExcel_Chart_DataSeriesValues('Number', 'Summary!$D$2:$D$5', null, 4),
/*
new PHPExcel_Chart_DataSeriesValues('Number', 'Summary!$C$2:$C$5', null, 5),
new PHPExcel_Chart_DataSeriesValues('Number', 'Summary!$D$2:$D$5', null, 5)
new PHPExcel_Chart_DataSeriesValues('Number', 'Summary!$E$2:$E$5', null, 5),
new PHPExcel_Chart_DataSeriesValues('Number', 'Summary!$F$2:$F$5', null, 5),
*/
);
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping
array(0, 1), // plotOrder
$labels, // plotLabel
$categories, // plotCategory
$values // plotValues
);
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
$plotarea = new PHPExcel_Chart_PlotArea(null, array($series));
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, null, false);
$chart = new PHPExcel_Chart(
'chart1', // name
null, // title
$legend, // legend
$plotarea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
null, // xAxisLabel
null // yAxisLabel
);
$chart->setTopLeftPosition('A7');
$chart->setBottomRightPosition('H20');
$excel->getActiveSheet()->addChart($chart);
$excel->getActiveSheet()->setTitle("Summary");