1
我試圖在通過PHPExcel生成的圖表上顯示X軸標籤。但它只給我默認名稱(1,2,3和Series1)而不是真實的標籤。PHPExcel:顯示圖表X軸標籤
這裏是我使用的代碼:
$xlsSheet->fromArray($exportAnswers, null, 'A1');
$dataseriesLabels = array(
new PHPExcel_Chart_DataSeriesValues('String', '!$A$2:$A$4', NULL, 3)
);
$xAxisTickValues = array(
new PHPExcel_Chart_DataSeriesValues('String', '!$A$2:$A$4', NULL, 3)
);
$dataSeriesValues = array(
new PHPExcel_Chart_DataSeriesValues('Number', '!$B$2:$B$4', NULL, 3)
);
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
NULL, // plotGrouping
range(0, count($dataSeriesValues) - 1), // plotOrder
$dataseriesLabels, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues, // plotValues
NULL
);
$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);
$title = new PHPExcel_Chart_Title($b['block_title']);
$chart = new PHPExcel_Chart(
$b['block_title'], // name
$title, // title
$legend, // legend
$plotarea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
NULL, // xAxisLabel
NULL // yAxisLabel
);
$chart->setTopLeftPosition('H2');
$chart->setBottomRightPosition('P20');
$xlsSheet->addChart($chart);
這裏是結果在Excel中:
非常感謝您的幫助!
謝謝SOOOO了! :) – mAydie