PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.5.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.5.1
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / phpoffice / phpspreadsheet / samples / Chart / 33_Chart_create_radar.php

33_Chart_create_radar.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.5.1, at vendor/phpoffice/phpspreadsheet/samples/Chart/33_Chart_create_radar.php

118 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use PhpOffice\PhpSpreadsheet\Chart\Chart;
4 use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
5 use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
6 use PhpOffice\PhpSpreadsheet\Chart\Layout;
7 use PhpOffice\PhpSpreadsheet\Chart\Legend;
8 use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
9 use PhpOffice\PhpSpreadsheet\Chart\Title;
10 use PhpOffice\PhpSpreadsheet\IOFactory;
11 use PhpOffice\PhpSpreadsheet\Spreadsheet;
12
13 require __DIR__ . '/../Header.php';
14
15 $spreadsheet = new Spreadsheet();
16 $worksheet = $spreadsheet->getActiveSheet();
17 $worksheet->fromArray(
18 [
19 ['', 2010, 2011, 2012],
20 ['Jan', 47, 45, 71],
21 ['Feb', 56, 73, 86],
22 ['Mar', 52, 61, 69],
23 ['Apr', 40, 52, 60],
24 ['May', 42, 55, 71],
25 ['Jun', 58, 63, 76],
26 ['Jul', 53, 61, 89],
27 ['Aug', 46, 69, 85],
28 ['Sep', 62, 75, 81],
29 ['Oct', 51, 70, 96],
30 ['Nov', 55, 66, 89],
31 ['Dec', 68, 62, 0],
32 ]
33 );
34
35 // Set the Labels for each data series we want to plot
36 // Datatype
37 // Cell reference for data
38 // Format Code
39 // Number of datapoints in series
40 // Data values
41 // Data Marker
42 $dataSeriesLabels = [
43 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011
44 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012
45 ];
46 // Set the X-Axis Labels
47 // Datatype
48 // Cell reference for data
49 // Format Code
50 // Number of datapoints in series
51 // Data values
52 // Data Marker
53 $xAxisTickValues = [
54 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec
55 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec
56 ];
57 // Set the Data values for each data series we want to plot
58 // Datatype
59 // Cell reference for data
60 // Format Code
61 // Number of datapoints in series
62 // Data values
63 // Data Marker
64 $dataSeriesValues = [
65 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$13', null, 12),
66 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$13', null, 12),
67 ];
68
69 // Build the dataseries
70 $series = new DataSeries(
71 DataSeries::TYPE_RADARCHART, // plotType
72 null, // plotGrouping (Radar charts don't have any grouping)
73 range(0, count($dataSeriesValues) - 1), // plotOrder
74 $dataSeriesLabels, // plotLabel
75 $xAxisTickValues, // plotCategory
76 $dataSeriesValues, // plotValues
77 null, // plotDirection
78 null, // smooth line
79 DataSeries::STYLE_MARKER // plotStyle
80 );
81
82 // Set up a layout object for the Pie chart
83 $layout = new Layout();
84
85 // Set the series in the plot area
86 $plotArea = new PlotArea($layout, [$series]);
87 // Set the chart legend
88 $legend = new Legend(Legend::POSITION_RIGHT, null, false);
89
90 $title = new Title('Test Radar Chart');
91
92 // Create the chart
93 $chart = new Chart(
94 'chart1', // name
95 $title, // title
96 $legend, // legend
97 $plotArea, // plotArea
98 true, // plotVisibleOnly
99 0, // displayBlanksAs
100 null, // xAxisLabel
101 null // yAxisLabel - Radar charts don't have a Y-Axis
102 );
103
104 // Set the position where the chart should appear in the worksheet
105 $chart->setTopLeftPosition('F2');
106 $chart->setBottomRightPosition('M15');
107
108 // Add the chart to the worksheet
109 $worksheet->addChart($chart);
110
111 // Save Excel 2007 file
112 $filename = $helper->getFilename(__FILE__);
113 $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
114 $writer->setIncludeCharts(true);
115 $callStartTime = microtime(true);
116 $writer->save($filename);
117 $helper->logWrite($writer, $filename, $callStartTime);
118