Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('inc_excel.php');
- $objPHPExcel = new PHPExcel();
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("PHPExcel Test Document")
- ->setSubject("PHPExcel Test Document")
- ->setDescription("Test document for PHPExcel, generated using PHP classes.")
- ->setKeywords("office PHPExcel php")
- ->setCategory("Test result file");
- //Tentukan target halamannya
- $objWorksheet = $objPHPExcel->getActiveSheet();
- //buat list datanya... yg pertama adalah judul dan sianya adalah datanya..
- $objWorksheet->fromArray(
- array(
- array('', 2010, 2011, 2012),
- array('Q1', 12, 15, 21),
- array('Q2', 56, 73, 86),
- array('Q3', 52, 61, 69),
- array('Q4', 30, 32, 0),
- )
- );
- //tentukan heder datanya, dalam hal ini tahunnya
- $dataSeriesLabels = array(
- new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // 2010
- new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011
- new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012
- );
- //tentukan rentang datanya.. lihat dari data ini maka yang di ambil adalah q1-q4
- $xAxisTickValues = array(
- new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4
- );
- //masukkan nilainya
- $dataSeriesValues = array(
- new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4),
- new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
- new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4),
- );
- //bangun grafiknya
- // Build the dataseries
- $series = new PHPExcel_Chart_DataSeries(
- PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
- PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
- range(0, count($dataSeriesValues)-1), // plotOrder
- $dataSeriesLabels, // plotLabel
- $xAxisTickValues, // plotCategory
- $dataSeriesValues // plotValues
- );
- //salah satu option
- $series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
- // 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);
- //judul
- $title = new PHPExcel_Chart_Title('Test Column Chart');
- $yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');
- //mulai membangun
- // Create the chart
- $chart = new PHPExcel_Chart(
- 'chart1', // name
- $title, // title
- $legend, // legend
- $plotArea, // plotArea
- true, // plotVisibleOnly
- 0, // displayBlanksAs
- NULL, // xAxisLabel
- $yAxisLabel // yAxisLabel
- );
- //meletakkan pada tempatnya dalam hal ini dari H1-P20
- // Set the position where the chart should appear in the worksheet
- $chart->setTopLeftPosition('H1');
- $chart->setBottomRightPosition('P20');
- //memasang
- // Add the chart to the worksheet
- $objWorksheet->addChart($chart);
- save_chart( $objPHPExcel, 'excel_graph.xlsx');
- echo "done <a href='excel_graph.xlsx'>download</a><hr/>";
- echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
- // Echo done
- echo date('H:i:s') , " Done writing file" , EOL;
- echo 'File has been created in ' , getcwd() , EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement