問題のライブラリはPHPExcel 1.7.7 です
codeplexのスレッドにあるサンプル コードを使用して、PHPExcelでグラフを作成しました。ただし、フォーラムで提示されたサンプル コードは 2 列のデータしか扱っていないため、グラフに表示される列の数を増やしたいと考えています。3 番目のデータ セット (列 D 以降) は、何をしようとしても表示されません。
ラベル/カテゴリの文字列に問題はありません。そのため、予約された名前との衝突はありません (文字列であっても)。plotValues を返して、何かが失われたかどうかを確認しましたが、定義された列が引き続き表示されますそこに表示されますが、3 番目の列がグラフに表示されない理由がわかりません。
$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");