$spreadsheet=newSpreadsheet();$worksheet=$spreadsheet->getActiveSheet();$worksheet->fromArray([['',2010,2011,2012],['Q1',12,15,21],['Q2',56,73,86],['Q3',52,61,69],['Q4',30,32,0],]);$dataSeriesLabels=[newDataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING,'Worksheet!$B$1',null,1),// 2010newDataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING,'Worksheet!$C$1',null,1),// 2011newDataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING,'Worksheet!$D$1',null,1),// 2012];$dataSeriesLabels[0]->setFillColor('FF0000');$xAxisTickValues=[newDataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING,'Worksheet!$A$2:$A$5',null,4),// Q1 to Q4];$dataSeriesValues=[newDataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER,'Worksheet!$B$2:$B$5',null,4),newDataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER,'Worksheet!$C$2:$C$5',null,4),newDataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER,'Worksheet!$D$2:$D$5',null,4),];$dataSeriesValues[2]->setLineWidth(60000/Properties::POINTS_WIDTH_MULTIPLIER);// Build the dataseries$series=newDataSeries(DataSeries::TYPE_LINECHART,// plotTypeDataSeries::GROUPING_STANDARD,// plotGroupingrange(0,count($dataSeriesValues)-1),// plotOrder$dataSeriesLabels,// plotLabel$xAxisTickValues,// plotCategory$dataSeriesValues,// plotValuesnull,true);$series->setPlotDirection(DataSeries::DIRECTION_COL);// 把值标注在上面// $layout1 = new Layout();// $layout1->setShowVal(true);// $layout1->setShowPercent(true);// $plotArea = new PlotArea($layout1, [$series]);// Set the series in the plot area$plotArea=newPlotArea(null,[$series]);// Set the chart legend$legend=newChartLegend(ChartLegend::POSITION_TOPRIGHT,null,false);$title=newTitle('Test Stacked Line Chart');$yAxisLabel=newTitle('Value ($k)');// Create the chart$chart=newChart('chart1',// name$title,// title$legend,// legend$plotArea,// plotAreatrue,// plotVisibleOnlyDataSeries::EMPTY_AS_GAP,// displayBlanksAsnull,// xAxisLabel$yAxisLabel// yAxisLabel);// Set the position where the chart should appear in the worksheet$chart->setTopLeftPosition('A7');$chart->setBottomRightPosition('o30');// Add the chart to the worksheet$worksheet->addChart($chart);// Save Excel 2007 file$filename="test";header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8');header('Content-Disposition: attachment;filename="'.$filename.'.xlsx"');header('Cache-Control: max-age=0');ob_end_clean();$writer=IOFactory::createWriter($spreadsheet,'Xlsx');$writer->setIncludeCharts(true);$writer->save("php://output");$spreadsheet->disconnectWorksheets();