function xxxbuildGraphic($stats) { $maior = 200; // maior valor $titulo = "Dados de acessos"; $stat = $stats->getRequests(); $q = count($stat); foreach ($stat as $s) { if ($year != $s->getYear()) { $height[$s->getYear()] = $s->getNumberOfRequests(); $year = $s->getYear(); } else { if ($height[$year] < $s->getNumberOfRequests()) { $height[$year] = $s->getNumberOfRequests(); } } } $totalHeight = array_sum($height); $years = count($height); $gbarras = new GraficoBarras($totalHeight, $years); $gbarras->setHeader(); $gbarras->adicionarTituloGrafico($titulo, "darker_red", "white"); $gbarras->setmaxvalor($maior); $arrayColors = array('red', 'green', 'yellow', 'blue', 'orange', 'purple', 'red', 'darker_green', 'darker_yellow', 'darker_blue', 'darker_orange', 'darker_purple'); $i = 0; $year = 0; foreach ($stat as $s) { if ($year == 0) { $year = $s->getYear(); } if ($year > 0 && $year != $s->getYear()) { $gbarras->criaLegenda('Legenda', "black", "black", "white"); $gbarras->criaGrafico(); $gbarras->desenhaGrafico(); $gbarras->resetData(); //die(); } $gbarras->setData($s->getNumberOfRequests(), $arrayColors[$i], $s->getMonth() . '/' . $s->getYear()); if ($i == count($arrayColors)) { $i = 0; } $i++; } if ($year > 0 && $year != $s->getYear()) { //$gbarras->criaLegenda('Legenda', "black", "black", "white"); $gbarras->criaGrafico(); $gbarras->desenhaGrafico(); } }
$y2 = $y1 + 20.1 * $this->num_barras; imagerectangle($this->imag, $x1, $y1, $x2, $y2, $this->dark_cores[2]); //caixa envolvente imagefilledrectangle($this->imag, $x1 + 1, $y1 + 1, $x2 - 1, $y2 - 1, $cor_legenda); $x1 += 10; for ($a = 0, $k = 5; $a < $this->num_barras; $a++, $k += 20) { imagefilledrectangle($this->imag, $x1, $y1 + $k, $x1 + $inc, $y1 + $k + $inc, $this->cores[$a]); imagerectangle($this->imag, $x1 - 1, $y1 + $k - 1, $x1 + $inc + 1, $y1 + $k + $inc + 1, $this->preto); imagestring($this->imag, 3, 38, $y1 + $k - 1, $this->arr_nomes[$a], $this->cor_letras); } } } // ------------- criar o grafico ------------- $maior = 100; // maior valor $titulo = "Perguntas por tipo"; $gbarras = new GraficoBarras(3, 420, 400, $estilo_s); $gbarras->adicionarTituloGrafico($titulo); $gbarras->setmaxvalor($maior); $gbarras->desenhaExterior(); $gbarras->desenhaEscVertical($maior); $gbarras->desenhaEscHorizontal(); $gbarras->addDados(100); $gbarras->addNomes("Benfica"); $gbarras->addDados(75); $gbarras->addNomes("Porto MFC"); $gbarras->addDados(50); $gbarras->addNomes("Juveo Gay"); $gbarras->criaGrafico(); $gbarras->criaLegenda(); $gbarras->desenhaGrafico();