Back to PhocacartStatistics class

Method renderChartJsPie

public
renderChartJsPie
(mixed $id, mixed $data, mixed $limit = 5)

Method renderChartJsPie - Source code

public function renderChartJsPie($id, $data, $limit = 5)
{
    $colors = array('#FFCC33', '#FF6633', '#FF3366', '#FF33CC', '#CC33FF');
    $dS = $lS = $bS = '';
    if (!empty($data)) {
        foreach ($data as $k => $v) {
            if ($k >= $limit) {
                break;
            }
            $d[$k] = '\'' . addslashes($v['items']) . '\'';
            $l[$k] = '\'' . addslashes($v['title']) . '\'';
            $c = $k % 5;
            $b[$k] = '\'' . addslashes($colors[$c]) . '\'';
        }
        $dS = implode(',', $d);
        $lS = implode(',', $l);
        $bS = implode(',', $b);
    }
    // labels: [".htmlspecialchars($lS, ENT_NOQUOTES, 'UTF-8')."]
    $o = "\r\nvar config" . $id . " = {\r\n\ttype: 'pie',\r\n\tdata: {\r\n\t\tdatasets: [{\r\n\t\t\tdata: [" . htmlspecialchars($dS) . "],\r\n\t\t\tbackgroundColor : [" . htmlspecialchars($bS) . "],\r\n\t\t}],\r\n\t\tlabels: [" . $lS . "]\r\n\t},\r\n\toptions: {\r\n\t\tresponsive: true,\r\n\t}\r\n};";
    Factory::getDocument()->addScriptDeclaration($o);
}