PHPExcel generating chart PHPExcel download
Example:
Line chart generation example:
GetActiveSheet (); $ data = array ("", "Class 1", "class 2", "Class 3"), array ("fail", 20, 30, 40), array ("good", 30, 50, 70), array ("excellent", 30); $ objSheet-> fromArray ($ data ); // Chart $ labels = array (new PHPExcel_Chart_DataSeriesValues ('string', 'worksheet! $ B $1 ', null, 1), // class 1 new PHPExcel_Chart_DataSeriesValues ('string', 'worksheet! $ C $1 ', null, 1), // class 2 new PHPExcel_Chart_DataSeriesValues ('string', 'worksheet! $ D $ 1', null, 1), // Class 3); $ xLabels = array (new PHPExcel_Chart_DataSeriesValues ('string', 'worksheet! $ A $2: $ A $ 4', null, 3), // take the X axis scale); $ datas = array (new PHPExcel_Chart_DataSeriesValues ('number', 'worksheet! $ B $2: $ B $4 ', null, 3), // get the first class of data new PHPExcel_Chart_DataSeriesValues ('number', 'worksheet! $ C $2: $ C $4 ', null, 3), // Obtain the second-class data new PHPExcel_Chart_DataSeriesValues ('number', 'worksheet! $ D $2: $ D $4 ', null, 3), // take three classes of data); $ series = array (new PHPExcel_Chart_DataSeries (PHPExcel_Chart_DataSeries: TYPE_LINECHART, PHPExcel_Chart_DataSeries :: GROUPING_STANDARD, range (0, count ($ labels)-1), $ labels, $ xLabels, $ datas); // Chart framework $ layout = new PHPExcel_Chart_Layout (); $ layout-> setShowVal (true); $ areas = new PHPExcel_Chart_PlotArea ($ layout, $ series); $ legend = new partition (PHPExcel_Chart_Legend: POSITION_RIGHT, $ layout, false ); $ title = new PHPExcel_Chart_Title (""); $ ytitle = new PHPExcel_Chart_Title (""); $ chart = new PHPExcel_Chart ('line _ chart', $ title, $ legend, $ areas, true, false, null, $ ytitle); $ chart-> setTopLeftPosition ("A7")-> setBottomRightPosition ("K25 "); // chart Position $ objSheet-> addChart ($ chart); $ excel = 'excel2007 '; $ objWriter = PHPExcel_IOFactory: createWriter ($ objPHPExcel, $ excel ); $ objWriter-> setIncludeCharts (true); // The Chart must be // $ objWriter-> save ($ dir. '/export.xls'); // Generate the excel file browser_export ($ excel, "browser_chart.xlsx"); // The browser outputs SaveViaTempFile ($ objWriter); function browser_export ($ type, $ filename) {if ($ type = "Excel5") {header ('content-Type: application/vnd. ms-excel '); // excel2003} else {header ('content-Type: application/vnd. openxmlformats-officedocument.spreadsheetml.sheet '); // excel2007} header ('content-Disposition: attachment; filename = "'. $ filename. '"'); header ('cache-Control: max-age = 0');}/* cannot export Excel2007 */function SaveViaTempFile ($ objWriter) {$ filePath = dirname (_ FILE __). rand (0, getrandmax ()). rand (0, getrandmax ()). ". tmp "; $ objWriter-> save ($ filePath); readfile ($ filePath); unlink ($ filePath );}
:
References:
PHPExcel
PHPExcel + MySQL
PHPExcel style
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.