有问题的库是PHPExcel 1.7.7
我使用了在codeplex的一个线程中找到的示例代码来使用 PHPExcel 创建图表。但是,论坛中提供的示例代码只处理两列数据,我希望扩大图表中显示的列数。无论我尝试如何处理第三组数据(D 列及以后)都不会显示。
标签/类别字符串没有问题 - 因此与任何保留名称都没有冲突(即使它们是字符串),我返回 plotValues 以查看是否丢失了任何内容,我仍然看到定义的列显示在那里,但无法弄清楚为什么图表中没有显示第三列。
$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");