The code is...
include($DOCUMENT_ROOT.'/system/classes/cria_grafico.php');
$arr=unserialize(stripslashes($var_contador));
$arr_legenda=$arr[0];
$arr_contador[0]=$arr[1];
$grafico = new cria_grafico();
$grafico->SetTitulo('Ranking');
$grafico->SetTipo($tipo);
$grafico->SetTipoFigura('bmp');
$grafico->SetData($arr_contador);
$grafico->SetLegenda($arr_legenda);
$grafico->SetXLabel('Conceitos');
if ($tipo != "pie") {
$grafico->SetYLabel('Percentuais');
}
$grafico->criar();
The cria_grafico.php file is...
include ($DOCUMENT_ROOT.'/system/phplot/phplot.php');
class cria_grafico
{
var $graph;
var $tipo;
var $data;
var $legenda;
var $titulo;
var $tipo_figura;
function cria_grafico()
{
$this->graph = new PHPlot(700,500);
}
function SetTipoFigura($tipo_figura)
{
$this->tipo_figura=$tipo_figura;
}
function SetTipo($tipo)
{
$this->tipo=$tipo;
}
function SetData($data)
{
$tam = count($data[0]);
for ($i = 0; $i < $tam; $i++) {
if ($data[0][$i]==0)
{
$newdata[0][$i] = '0,05';
}
else
{
$newdata[0][$i] = $data[0][$i];
}
}
$this->data=$newdata;
}
function SetLegenda($legenda)
{
$this->legenda=$legenda;
}
function SetTitulo($titulo)
{
$this->titulo=$titulo;
}
function SetXLabel($xlabel)
{
$this->xlabel=$xlabel;
}
function SetYLabel($ylabel)
{
$this->ylabel=$ylabel;
}
function SetYLabel($ylabel)
{
$this->ylabel=$ylabel;
}
function criar()
{
if (isset($this->tipo))
{
//tipo de grafico
$this->graph->SetPlotType($this->tipo);
}
else
{
echo "Erro de parametro. SetTipo.";
exit();
}
if (isset($this->data))
{
if($this->tipo=="bars")
{
//seta os valores para o grafico
$this->graph->SetDataValues($this->data);
}
else
{
//seta os valores para o grafico
$this->data[1]=$this->data[0];
$this->graph->SetDataValues($this->data);
}
}
else
{
echo "Erro de parametro. SetData.";
exit();
}
//posicao da legenda
$this->graph->SetLegendPixels(597,0.1,0,0);
//titulo para o grafico
if (isset($this->titulo))
$this->graph->SetTitle($this->titulo);
if (isset($this->xlabel))
$this->graph->SetXLabel($this->xlabel);
if (isset($this->ylabel))
$this->graph->SetYLabel($this->ylabel);
$this->graph->SetLabelScalePosition(1.18);
if (isset($this->legenda))
$this->graph->SetLegend($this->legenda);
$this->graph->SetBackgroundColor('white');
$this->graph->SetPlotBgColor('pink');
$this->graph->DrawGraph();
}
}
Thanks for your help
