這裏是條形圖
// Set the Labels for each data series we want to plot
// Datatype
// Cell reference for data
// Format Code
// Number of datapoints in series
// Data values
// Data Marker
$dataSeriesLabels = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Data!$D$1', NULL, 1), // 2011
);
// Set the X-Axis Labels
// Datatype
// Cell reference for data
// Format Code
// Number of datapoints in series
// Data values
// Data Marker
$xAxisTickValues = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Data!$A$2:$A$5', NULL, 6), // Q1 to Q4
);
// Set the Data values for each data series we want to plot
// Datatype
// Cell reference for data
// Format Code
// Number of datapoints in series
// Data values
// Data Marker
$dataSeriesValues = array(
new PHPExcel_Chart_DataSeriesValues('Number', 'Data!$D$2:$D$5', NULL, 6),
);
// Build the dataseries
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping
range(0, count($dataSeriesValues)-1), // plotOrder
$dataSeriesLabels, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues // plotValues
);
// Set additional dataseries parameters
// Set the series in the plot area
$plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series));
// Set the chart legend
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
$title = new PHPExcel_Chart_Title('Topic Relevance');
$yAxisLabel = new PHPExcel_Chart_Title('Points');
// Create the chart
$chart = new PHPExcel_Chart(
'chart1', // name
$title, // title
$legend, // legend
$plotArea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
NULL, // xAxisLabel
$yAxisLabel // yAxisLabel
);
// Set the position where the chart should appear in the worksheet
$chart->setTopLeftPosition('B10');
$chart->setBottomRightPosition('F25');
// Add the chart to the worksheet
$objWorksheet->addChart($chart);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//this line is necessary to display chart in excel
$objWriter->setIncludeCharts(TRUE);
你看任何的PHPExcel圖表示例代碼?他們展示瞭如何創建大多數類型的圖表 –
你有什麼鏈接?我做了檢查,但不明白。 –
[圖表創建示例](https://github.com/PHPOffice/PHPExcel/tree/1.8/Examples)與像'33chartcreate-bar.php'文件名 –