有問題的圖書館是PHPExcel 1.7.7PHPExcel - 所有值圖表
我用在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");
你有設置plotOrder包括其他地塊即數組(0,1,2)? – Robbie
@Robbie - 那個伎倆 - 謝謝 - 不知道plotOrder的意思是什麼。如果您以此作爲答案 - 我會將您標記爲正確答案。如果沒有,那麼馬克貝克將獲得信貸。 – Duniyadnd
謝謝。設置馬克是正確的,沒有一點有兩個答案說同樣的事情,他更好地解釋它! – Robbie