';
switch ($_config["charts"]) {
case "doughnut":
echo self::javascriptDoughnut($_config);
break;
case "bar":
echo self::javascriptBar($_config);
break;
case "line":
echo self::javascriptLine($_config);
break;
default:
break;
}
}
private static function constructData(array $_data)
{
$label = $nb = $backgroundColor = $borderColor = "";
$opacity = 0.5;
$nbData = count($_data);
$data["backgroundColor"] = array(
"rgba(255, 99, 132, " . $opacity . ")", // Red
"rgba(54, 162, 235, " . $opacity . ")", // Blue
"rgba(255, 206, 86, " . $opacity . ")", // Yellow
"rgba(75, 192, 192, " . $opacity . ")", // Green,
"rgba(153, 102, 255, " . $opacity . ")", // Purple
"rgba(255, 159, 64, " . $opacity . ")" // Orange
);
$data["borderColor"] = array(
"rgba(255,99,132,1)", // Red
"rgba(54, 162, 235, 1)", // Blue
"rgba(255, 206, 86, 1)", // Yellow
"rgba(75, 192, 192, 1)", // Green
"rgba(153, 102, 255, 1)", // Purple
"rgba(255, 159, 64, 1)" // Orange
);
for ($i = 0; $i < $nbData; $i++) {
$backgroundColor .= '"' . $data["backgroundColor"][$i] . '"';
if ($i != $nbData) {
$backgroundColor .= ", ";
}
}
for ($i = 0; $i < $nbData; $i++) {
$borderColor .= '"' . $data["borderColor"][$i] . '"';
if ($i != $nbData) {
$borderColor .= ", ";
}
}
for ($i = 0; $i < $nbData; $i++) {
$label .= '"' . $_data[$i]["label"] . '"';
if ($i != $nbData) {
$label .= ", ";
}
}
for ($i = 0; $i < $nbData; $i++) {
$nb .= '"' . $_data[$i]["nb"] . '"';
if ($i != $nbData) {
$nb .= ", ";
}
}
return array("label" => $label, "nb" => $nb, "backgroundColor" => $backgroundColor, "borderColor" => $borderColor);
}
private static function javascriptDoughnut(array $_config)
{
$sort = self::constructData($_config["data"]);
return '';
}
private static function javascriptBar(array $_config)
{
$sort = self::constructData($_config["data"]);
return '';
}
private static function constructDataLine(array $_data)
{
$return["labels"] = $return["data"] = NULL;
foreach ($_data[0] as $key => $value) {
$return["labels"] .= '"' . $key . '", ';
$return["data"] .= $value . ', ';
}
return $return;
}
private static function javascriptLine(array $_config)
{
$sort = self::constructDataLine($_config["data"]);
return '';
}
}