This repository has been archived by the owner on Nov 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
writeReportItem.php
82 lines (59 loc) · 2 KB
/
writeReportItem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
function writeReportItem( $args ) {
/**
* Write the report item to the screen using the data passed to it.
*
* @param string $title Chart title.
* @param string $caption Chart caption.
* @param string $type Chart type ('line', default, or 'bar').
* @param array $data Array with chart data.
* @param array $chartSeriesLabels Array with chart series labels.
* @param array $chartAxisLabels Array with x-axis labels.
* @param int $axisYMaxValue Sets the y-axis maximum value.
*/
// DEBUG
/* ?><pre><?php print_r( $args ); ?></pre><?php */
extract( $args );
ob_start();
// generate a unique name for the canvas
// remove any html tags that may be in the chart title
$canvasName = strip_tags($title);
// remove any special characters that may remain
$canvasName = preg_replace('/[^A-Za-z0-9\-]/', '', $canvasName);
$canvasName = str_replace(' ', '', $canvasName); // remove spaces
$canvasName = strtolower($canvasName); // make lowercase
$canvasName = $canvasName . '-' . rand(1000,9999); // add random numbers
$canvasName = $canvasName . '-' . uniqid(); // add a uniqid to help avoid collisions
?><h2 class="chartTitle"><?php echo $title; ?></h2><?php
// if there is a report caption, write it
if ( !empty($caption) ) {
?><p><?php echo $caption; ?></p><?php
}
// DEBUG
// echo '<pre>Canvas name = [' . $canvasName . ']</pre>';
?>
<div class="reportItem">
<?php
echo writeChart( array(
// "chartTitle" => "Actual data",
"chartID" => $canvasName,
"chartType" => $type,
"reportData" => $data,
"chartSeriesLabels" => $chartSeriesLabels,
"chartAxisLabels" => $chartAxisLabels,
"axisYMaxValue" => $axisYMaxValue,
"backgroundColor" => $backgroundColor,
) );
echo writeTable( array(
"reportData" => $data,
"reportDataYOY" => $dataYOY,
"chartSeriesLabels" => $chartSeriesLabels,
"chartAxisLabels" => $chartAxisLabels,
) );
?>
</div>
<hr>
<?php
$out = ob_get_clean();
return $out;
}