|
|
@@ -12,6 +12,12 @@ class chart
|
|
|
$width = (isset($_config["width"])) ? $_config["width"] : 600;
|
|
|
$height = (isset($_config["height"])) ? $_config["height"] : 400;
|
|
|
|
|
|
+ if(!empty($_config["config"])){
|
|
|
+ $_config["config"] = core::extractArrayInArray($_config["config"]);
|
|
|
+ } else {
|
|
|
+ $_config["config"] = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
echo '<canvas id="' . $id . '" width="' . $width . '" height="' . $height . '" style="display: block; width: ' . $width . 'px; height: ' . $height . 'px;" class="chartjs-render-monitor"></canvas>';
|
|
|
|
|
|
switch ($_config["charts"]) {
|
|
|
@@ -24,64 +30,72 @@ class chart
|
|
|
case "line":
|
|
|
echo self::javascriptLine($_config);
|
|
|
break;
|
|
|
+ case "pie":
|
|
|
+ echo self::javascriptPie($_config);
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static function constructData(array $_data)
|
|
|
+ private static function constructData(array $_data, ?array $_config = NULL)
|
|
|
{
|
|
|
$label = $nb = $backgroundColor = $borderColor = "";
|
|
|
- $opacity = 0.5;
|
|
|
$nbData = count($_data);
|
|
|
|
|
|
-
|
|
|
- $data["backgroundColor"] = array(
|
|
|
- "rgba(242, 84, 84, 0.6)",
|
|
|
- "rgba(242, 132, 84, 0.6)",
|
|
|
- "rgba(242, 179, 84, 0.6)",
|
|
|
- "rgba(242, 226, 84, 0.6)",
|
|
|
- "rgba(210, 242, 84, 0.6)",
|
|
|
- "rgba(163, 242, 84, 0.6)",
|
|
|
- "rgba(116, 242, 84, 0.6)",
|
|
|
- "rgba(84, 242, 100, 0.6)",
|
|
|
- "rgba(84, 242, 147, 0.6)",
|
|
|
- "rgba(84, 242, 195, 0.6)",
|
|
|
- "rgba(84, 242, 242, 0.6)",
|
|
|
- "rgba(84, 195, 242, 0.6)",
|
|
|
- "rgba(84, 147, 242, 0.6)",
|
|
|
- "rgba(84, 100, 242, 0.6)",
|
|
|
- "rgba(116, 84, 242, 0.6)",
|
|
|
- "rgba(163, 84, 242, 0.6)",
|
|
|
- "rgba(210, 84, 242, 0.6)",
|
|
|
- "rgba(242, 84, 226, 0.6)",
|
|
|
- "rgba(242, 84, 179, 0.6)",
|
|
|
- "rgba(242, 84, 132, 0.6)"
|
|
|
- );
|
|
|
-
|
|
|
-
|
|
|
- $data["borderColor"] = array(
|
|
|
- "rgba(242, 84, 84, 1.0)",
|
|
|
- "rgba(242, 132, 84, 1.0)",
|
|
|
- "rgba(242, 179, 84, 1.0)",
|
|
|
- "rgba(242, 226, 84, 1.0)",
|
|
|
- "rgba(210, 242, 84, 1.0)",
|
|
|
- "rgba(163, 242, 84, 1.0)",
|
|
|
- "rgba(116, 242, 84, 1.0)",
|
|
|
- "rgba(84, 242, 100, 1.0)",
|
|
|
- "rgba(84, 242, 147, 1.0)",
|
|
|
- "rgba(84, 242, 195, 1.0)",
|
|
|
- "rgba(84, 242, 242, 1.0)",
|
|
|
- "rgba(84, 195, 242, 1.0)",
|
|
|
- "rgba(84, 147, 242, 1.0)",
|
|
|
- "rgba(84, 100, 242, 1.0)",
|
|
|
- "rgba(116, 84, 242, 1.0)",
|
|
|
- "rgba(163, 84, 242, 1.0)",
|
|
|
- "rgba(210, 84, 242, 1.0)",
|
|
|
- "rgba(242, 84, 226, 1.0)",
|
|
|
- "rgba(242, 84, 179, 1.0)",
|
|
|
- "rgba(242, 84, 132, 1.0)"
|
|
|
- );
|
|
|
+ if(empty($_config["backgroundColor"])){
|
|
|
+ $data["backgroundColor"] = array(
|
|
|
+ "rgba(242, 84, 84, 0.6)",
|
|
|
+ "rgba(242, 132, 84, 0.6)",
|
|
|
+ "rgba(242, 179, 84, 0.6)",
|
|
|
+ "rgba(242, 226, 84, 0.6)",
|
|
|
+ "rgba(210, 242, 84, 0.6)",
|
|
|
+ "rgba(163, 242, 84, 0.6)",
|
|
|
+ "rgba(116, 242, 84, 0.6)",
|
|
|
+ "rgba(84, 242, 100, 0.6)",
|
|
|
+ "rgba(84, 242, 147, 0.6)",
|
|
|
+ "rgba(84, 242, 195, 0.6)",
|
|
|
+ "rgba(84, 242, 242, 0.6)",
|
|
|
+ "rgba(84, 195, 242, 0.6)",
|
|
|
+ "rgba(84, 147, 242, 0.6)",
|
|
|
+ "rgba(84, 100, 242, 0.6)",
|
|
|
+ "rgba(116, 84, 242, 0.6)",
|
|
|
+ "rgba(163, 84, 242, 0.6)",
|
|
|
+ "rgba(210, 84, 242, 0.6)",
|
|
|
+ "rgba(242, 84, 226, 0.6)",
|
|
|
+ "rgba(242, 84, 179, 0.6)",
|
|
|
+ "rgba(242, 84, 132, 0.6)"
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ $data["backgroundColor"] = $_config["backgroundColor"];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($_config["borderColor"])){
|
|
|
+ $data["borderColor"] = array(
|
|
|
+ "rgba(242, 84, 84, 1.0)",
|
|
|
+ "rgba(242, 132, 84, 1.0)",
|
|
|
+ "rgba(242, 179, 84, 1.0)",
|
|
|
+ "rgba(242, 226, 84, 1.0)",
|
|
|
+ "rgba(210, 242, 84, 1.0)",
|
|
|
+ "rgba(163, 242, 84, 1.0)",
|
|
|
+ "rgba(116, 242, 84, 1.0)",
|
|
|
+ "rgba(84, 242, 100, 1.0)",
|
|
|
+ "rgba(84, 242, 147, 1.0)",
|
|
|
+ "rgba(84, 242, 195, 1.0)",
|
|
|
+ "rgba(84, 242, 242, 1.0)",
|
|
|
+ "rgba(84, 195, 242, 1.0)",
|
|
|
+ "rgba(84, 147, 242, 1.0)",
|
|
|
+ "rgba(84, 100, 242, 1.0)",
|
|
|
+ "rgba(116, 84, 242, 1.0)",
|
|
|
+ "rgba(163, 84, 242, 1.0)",
|
|
|
+ "rgba(210, 84, 242, 1.0)",
|
|
|
+ "rgba(242, 84, 226, 1.0)",
|
|
|
+ "rgba(242, 84, 179, 1.0)",
|
|
|
+ "rgba(242, 84, 132, 1.0)"
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ $data["borderColor"] = $_config["borderColor"];
|
|
|
+ }
|
|
|
|
|
|
for ($i = 0; $i < $nbData; $i++) {
|
|
|
$backgroundColor .= '"' . $data["backgroundColor"][$i] . '"';
|
|
|
@@ -98,7 +112,7 @@ class chart
|
|
|
}
|
|
|
|
|
|
for ($i = 0; $i < $nbData; $i++) {
|
|
|
- $label .= '"' . $_data[$i]["label"] . '"';
|
|
|
+ $label .= ($_data[$i]["nb"] > 0) ? '"' . $_data[$i]["label"] . '"' : '"Aucun(e)s ' . $_data[$i]["label"] . '"';
|
|
|
if ($i != $nbData) {
|
|
|
$label .= ", ";
|
|
|
}
|
|
|
@@ -114,10 +128,33 @@ class chart
|
|
|
return array("label" => $label, "nb" => $nb, "backgroundColor" => $backgroundColor, "borderColor" => $borderColor);
|
|
|
}
|
|
|
|
|
|
+ private static function javascriptPie(array $_config)
|
|
|
+ {
|
|
|
+
|
|
|
+ $sort = self::constructData($_config["data"], $_config["config"]);
|
|
|
+
|
|
|
+ return '<script>
|
|
|
+ var ctx = document.getElementById("' . $_config["id"] . '");
|
|
|
+ var myChart = new Chart(ctx, {
|
|
|
+ type: "pie",
|
|
|
+ data: {
|
|
|
+ labels: [' . $sort["label"] . '],
|
|
|
+ datasets: [{
|
|
|
+ label: "' . $_config["label"] . '",
|
|
|
+ data: [' . $sort["nb"] . '],
|
|
|
+ backgroundColor: [' . $sort["backgroundColor"] . '],
|
|
|
+ borderColor: [' . $sort["borderColor"] . '],
|
|
|
+ borderWidth: 1
|
|
|
+ }]
|
|
|
+ }
|
|
|
+ });
|
|
|
+ </script>';
|
|
|
+ }
|
|
|
+
|
|
|
private static function javascriptDoughnut(array $_config)
|
|
|
{
|
|
|
|
|
|
- $sort = self::constructData($_config["data"]);
|
|
|
+ $sort = self::constructData($_config["data"], $_config["config"]);
|
|
|
|
|
|
return '<script>
|
|
|
var ctx = document.getElementById("' . $_config["id"] . '");
|
|
|
@@ -140,7 +177,7 @@ class chart
|
|
|
private static function javascriptBar(array $_config)
|
|
|
{
|
|
|
|
|
|
- $sort = self::constructData($_config["data"]);
|
|
|
+ $sort = self::constructData($_config["data"], $_config["config"]);
|
|
|
|
|
|
return '<script>
|
|
|
var ctx = document.getElementById("' . $_config["id"] . '");
|
|
|
@@ -193,4 +230,5 @@ class chart
|
|
|
});
|
|
|
</script>';
|
|
|
}
|
|
|
+
|
|
|
}
|