Example #1
0
function barcart($datay)
{
    require_once "jpgraph/jpgraph.php";
    require_once "jpgraph/jpgraph_bar.php";
    // Setup the graph.
    $graph = new Graph(660, 250);
    $graph->SetScale("textlin");
    // Add a drop shadow
    $graph->SetShadow();
    // Adjust the margin a bit to make more room for titles
    $graph->SetMargin(40, 30, 20, 40);
    // Setup the titles
    $graph->title->Set('NHR Registry');
    $graph->xaxis->title->Set('X-title');
    $graph->yaxis->title->Set('Y-title');
    // Create the bar pot
    $bplot = new BarPlot($datay);
    // Adjust fill color
    $bplot->SetFillColor('orange');
    $graph->Add($bplot);
    $graph->title->SetFont(FF_FONT1, FS_BOLD);
    $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
    $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
    return $graph;
}
Example #2
0
 function plot($pid)
 {
     $this->_setValues($pid);
     $graph = new Graph(600, 400);
     $graph->img->SetMargin(60, 95, 40, 40);
     $graph->SetShadow();
     $graph->SetScale("textlog");
     $colors = array("yellow", "green", "blue", "red");
     srand(1);
     for ($i = 0; $i < sizeof($this->_data); $i++) {
         $bplot[$i] = new BarPlot($this->_data[$i]);
         $color = $colors[$i];
         $bplot[$i]->SetFillColor($color);
         $bplot[$i]->SetLegend($this->_legend[$i]);
     }
     $gbplot = new GroupBarPlot($bplot);
     $graph->Add($gbplot);
     $graph->title->Set("# of Visited Articles per Language (log scale)");
     $graph->title->SetFont(FONT2_BOLD);
     $graph->xaxis->SetTickLabels($this->_years);
     $graph->ygrid->Show(true, true);
     $graph->xaxis->SetFont(FONT1_BOLD);
     $graph->yaxis->SetFont(FONT1_BOLD);
     $graph->Stroke();
 }
 function plot($pid)
 {
     $this->_setValues($pid);
     $graph = new Graph(600, 400);
     $graph->img->SetMargin(60, 95, 40, 40);
     $graph->SetShadow();
     $graph->SetScale("textlog");
     $colors = array("hotpink", "green", "blue", "gold", "blueviolet", "deepskyblue", "brown", "cadetblue", "darksalmon", "cornflowerblue", "darkslateblue", "limegreen", "yellow", "navy", "slategray");
     srand(1);
     for ($i = 0; $i < sizeof($this->_data); $i++) {
         $bplot[$i] = new BarPlot($this->_data[$i]);
         if ($i < sizeof($colors)) {
             $color = $colors[$i];
         } else {
             $r = rand(0, 255);
             $g = rand(0, 255);
             $b = rand(0, 255);
             $color = array($r, $g, $b);
         }
         $bplot[$i]->SetFillColor($color);
         $bplot[$i]->SetLegend($this->_legend[$i]);
     }
     $gbplot = new GroupBarPlot($bplot);
     $graph->Add($gbplot);
     $graph->title->Set("# of Visited Articles per Month (log scale)");
     $graph->title->SetFont(FONT2_BOLD);
     $graph->xaxis->SetTickLabels($this->_months);
     $graph->ygrid->Show(true, true);
     $graph->xaxis->SetFont(FONT1_BOLD);
     $graph->yaxis->SetFont(FONT1_BOLD);
     $graph->Stroke();
 }
Example #4
0
 public function barGraph_2($data, $examinee_id, $color = 'green')
 {
     require_once '../app/classes/jpgraph/jpgraph_bar.php';
     // Create the graph. These two calls are always required
     $graph = new Graph(400, 334);
     $graph->SetScale('textlin');
     $graph->SetShadow(true, 5, 'white');
     // Adjust the margin a bit to make more room for titles
     $graph->SetMargin(40, 30, 20, 40);
     $graph->SetFrame(true, 'black', 1);
     // Create a bar pot
     $datay = array();
     $datalabel = array();
     foreach ($data as $value) {
         $datay[] = $value['score'];
         $datalabel[] = $value['chs_name'];
     }
     $bplot = new BarPlot($datay);
     // Adjust fill color
     $bplot->SetFillColor($color);
     $bplot->SetShadow("white");
     $graph->Add($bplot);
     // Setup labels
     $lbl = $datalabel;
     $graph->xaxis->SetTickLabels($lbl);
     $graph->xaxis->SetFont(FF_CHINESE, FS_BOLD, 12);
     // Send back the HTML page which will call this script again
     // to retrieve the image.
     //临时文件命名规范    $examinee_id_$date_rand(100,900)
     $date = date('H_i_s');
     $stamp = rand(100, 900);
     $fileName = './tmp/' . $examinee_id . '_' . $date . '_' . $stamp . '.jpeg';
     $graph->Stroke($fileName);
     return $fileName;
 }
 public function index()
 {
     // We want a bar graph, so use JpGraph's bar chart library
     require_once APPPATH . '/libraries/JpGraph/jpgraph_bar.php';
     // Example data (04/2015)
     $json = '[{"Hogwarts Academy":{"Yield":"19021 kWh","Yield specific":"127.01 kWh\\/kWp","Target yield":"16069.23 kWh","Current-target yield %":"<span style=\\"color: #3ab121\\">118.37 %<span>"}},{"cols": [{"id":"","label":"Time","pattern":"","type":"string"},{"id":"","label":"Hogwarts Academy (AC)","pattern":"","type":"number"},{"id":"","label":"Target values","pattern":"","type":"number"}], "rows": [{"c":[{"v":"01/04","f":null}, {"v":615.8,"f":"615,80 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"02/04","f":null}, {"v":712.5,"f":"712,50 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"03/04","f":null}, {"v":171,"f":"171,00 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"04/04","f":null}, {"v":382.3,"f":"382,30 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"05/04","f":null}, {"v":606.3,"f":"606,30 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"06/04","f":null}, {"v":774.5,"f":"774,50 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"07/04","f":null}, {"v":570.6,"f":"570,60 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"08/04","f":null}, {"v":726.8,"f":"726,80 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"09/04","f":null}, {"v":789.2,"f":"789,20 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"10/04","f":null}, {"v":592.9,"f":"592,90 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"11/04","f":null}, {"v":677.1,"f":"677,10 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"12/04","f":null}, {"v":244.5,"f":"244,50 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"13/04","f":null}, {"v":457.4,"f":"457,40 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"14/04","f":null}, {"v":340.8,"f":"340,80 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"15/04","f":null}, {"v":425.3,"f":"425,30 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"16/04","f":null}, {"v":828.8,"f":"828,80 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"17/04","f":null}, {"v":616.8,"f":"616,80 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"18/04","f":null}, {"v":660.3,"f":"660,30 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"19/04","f":null}, {"v":453.2,"f":"453,20 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"20/04","f":null}, {"v":691.9,"f":"691,90 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"21/04","f":null}, {"v":904.4,"f":"904,40 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"22/04","f":null}, {"v":879.1,"f":"879,10 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"23/04","f":null}, {"v":824.8,"f":"824,80 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"24/04","f":null}, {"v":777.9,"f":"777,90 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"25/04","f":null}, {"v":413.8,"f":"413,80 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"26/04","f":null}, {"v":834.8,"f":"834,80 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"27/04","f":null}, {"v":920.8,"f":"920,80 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"28/04","f":null}, {"v":751,"f":"751,00 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"29/04","f":null}, {"v":737.7,"f":"737,70 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]},{"c":[{"v":"30/04","f":null}, {"v":638.7,"f":"638,70 kWh"}, {"v":535.640966432,"f":"535,64 kWh"}]}]}]';
     // Turn string into object
     $obj = json_decode($json);
     // Stores for graph data
     $xdata = array();
     $ydata = array();
     // Get coords data from object
     $obj_data = $obj[1]->rows;
     $counter = 1;
     // Add it to each of our storage arrays
     foreach ($obj_data as $data) {
         // only plot when there is a kW value
         if (isset($data->c[1]->v)) {
             $xdata[] = $data->c[0]->v;
             // date
             $ydata[] = $data->c[1]->v;
             // kw
         }
     }
     // Create the graph.
     // One minute timeout for the cached image
     // INLINE_NO means don't stream it back to the browser.
     $graph = new Graph(600, 350, 'auto');
     $graph->SetScale("textlin");
     $graph->img->SetMargin(60, 30, 20, 40);
     $graph->yaxis->SetTitleMargin(45);
     $graph->yaxis->scale->SetGrace(30);
     $graph->SetShadow();
     // Turn the tickmarks
     $graph->xaxis->SetTickSide(SIDE_DOWN);
     $graph->yaxis->SetTickSide(SIDE_LEFT);
     // Create a bar pot
     $bplot = new BarPlot($ydata);
     $bplot->SetFillColor("orange");
     // Use a shadow on the bar graphs (just use the default settings)
     $bplot->SetShadow();
     $bplot->value->SetFormat(" %2.1f kW", 70);
     $bplot->value->SetFont(FF_VERDANA, FS_NORMAL, 8);
     $bplot->value->SetColor("blue");
     $bplot->value->Show();
     $graph->Add($bplot);
     $graph->title->Set("Hogwarts Academy");
     $graph->xaxis->title->Set("Day");
     $graph->yaxis->title->Set("Yield in kilowatt hours");
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     // Send back the HTML page which will call this script again
     // to retrieve the image.
     $graph->StrokeCSIM();
 }
function makeGraph($x_data, $y_data, $num_results, $title = "Statistics", $graph_type = "bar", $graph_scale = "textint")
{
    // default graph info
    $width = 600;
    $height = 500;
    $top = 60;
    $bottom = 30;
    $left = 80;
    $right = 30;
    if ($graph_type != 'csv' && $num_results == 0) {
        header('Content-type: image/png');
        readfile($GLOBALS['BASE_DIR'] . '/images/no-calls.png');
        exit;
    }
    // Set the basic parameters of the graph
    switch ($graph_type) {
        case "line":
            //do line graph here
            break;
            // not really a graph, returns comma seperated values
        // not really a graph, returns comma seperated values
        case "csv":
            header("content-type: text/csv");
            header('Content-Disposition: attachment; filename="statistics.csv"');
            $columns = implode(',', $x_data);
            $rows = implode(',', $y_data);
            echo $columns . "\n" . $rows;
            break;
        case "bar":
        default:
            // bar is default
            $graph = new Graph($width, 90 + 10 * $num_results, 'auto');
            $graph->SetScale($graph_scale);
            // Nice shadow
            $graph->SetShadow();
            $graph->Set90AndMargin($left, $right, $top, $bottom);
            // Setup labels
            $graph->xaxis->SetTickLabels($x_data);
            // Label align for X-axis
            $graph->xaxis->SetLabelAlign('right', 'center', 'right');
            // Label align for Y-axis
            $graph->yaxis->SetLabelAlign('center', 'bottom');
            // Create a bar pot
            $bplot = new BarPlot($y_data);
            $bplot->SetFillColor("#708090");
            $bplot->SetWidth(0.5);
            $bplot->SetYMin(0);
            //$bplot->SetYMin(1990);
            $graph->title->Set($title);
            $graph->Add($bplot);
            $graph->Stroke();
    }
}
 /**
  *
  */
 public function iterationSummary($id)
 {
     $iteration = Iterations::findOrFail($id);
     $issues = Issue::where('iterationid', '=', $iteration->id)->get();
     $tasksId = array();
     foreach ($issues as $issue) {
         $tasksId[] = $issue->id;
     }
     $tasks = Task::whereIn('issueid', $tasksId)->get();
     $countTODO = 0;
     $countDOING = 0;
     $countDONE = 0;
     foreach ($tasks as $task) {
         switch ($task->scrumid) {
             case 1:
                 $countTODO++;
                 break;
             case 2:
                 $countDOING++;
                 break;
             case 3:
                 $countDONE++;
                 break;
         }
     }
     JpGraph\JpGraph::load();
     JpGraph\JpGraph::module('bar');
     $l1datay = array($countTODO, $countDOING, $countDONE);
     //$datax=array('TO-DO','DOING','DONE');
     $datax = array('POR HACER', 'HACIENDO', 'HECHAS');
     //Create the graph
     $graph = new Graph(700, 300);
     $graph->SetScale('textlin');
     $graph->img->SetMargin(60, 130, 40, 60);
     $graph->SetShadow();
     // Create the linear error plot
     $l1plot = new BarPlot($l1datay);
     $l1plot->SetColor('red');
     $l1plot->SetWeight(2);
     $l1plot->SetLegend('Avance de iteracion');
     // Add the plots to t'he graph
     $graph->Add($l1plot);
     $graph->xaxis->SetTickLabels($datax);
     $graph->title->Set('Tareas');
     //$graph->xaxis->title->Set('Estados');
     //$graph->yaxis->title->Set('Cantidad');
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     //Display the graph
     $graph->Stroke();
 }
 public function bar_task($id)
 {
     $help = new Helper();
     $issues = $help->searchIssues($id);
     //foreach ($issues as $issue) {
     # code...
     //	$issue->id
     //}
     //$iteration = Iterations::findOrFail($id);
     //$idTmp = $iteration->id;
     // $issues = Issue::where('iterationid','=', $idTmp)->get();
     //$issues = $iteration->issues;
     //$countIssues = sizeof($issues);
     $countIssues = 0;
     $dataEstimatedTime = array();
     $dataRealTime = array();
     $dataIterationName = array();
     $countTODO = 0;
     $countDOING = 0;
     $countDONE = 0;
     //$string_iterations = implode(";", $iterations);
     JpGraph\JpGraph::load();
     JpGraph\JpGraph::module('bar');
     JpGraph\JpGraph::module('line');
     $datay = array(12, 8, 19, 3, 10, 5);
     // Create the graph. These two calls are always required
     $graph = new Graph(300, 200);
     $graph->SetScale('textlin');
     // Add a drop shadow
     $graph->SetShadow();
     // Adjust the margin a bit to make more room for titles
     $graph->SetMargin(40, 30, 20, 40);
     // Create a bar pot
     $bplot = new BarPlot($datay);
     // Adjust fill color
     $bplot->SetFillColor('orange');
     $graph->Add($bplot);
     // Setup the titles
     $graph->title->Set('A basic bar graph ');
     $graph->xaxis->title->Set('X-title');
     $graph->yaxis->title->Set('Y-title');
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     //$graph->Stroke();
     //$response = Response::make(
     //     $graph->Stroke()
     //);
     //    	$response->header('content-type', 'image/png');
     //  	return $response;
 }
function LineGraph($w, $h, $title, $data1, $data2, $datax, $output)
{
    // Create the graph. These two calls are always required
    $graph = new Graph($w, $h, "auto");
    $graph->SetScale("textlin");
    $graph->SetMarginColor('white');
    $graph->SetFrame(true);
    // Adjust the margin
    $graph->img->SetMargin(40, 100, 20, 40);
    $graph->SetShadow(false);
    // Create the linear plot
    $lineplot = new LinePlot($data1);
    $lineplot->SetWeight(2);
    $lineplot->SetColor("blue");
    $lineplot->mark->SetType(MARK_DIAMOND);
    $lineplot->mark->SetWidth(5);
    $lineplot->mark->SetFillColor('blue');
    $lineplot->value->SetMargin(-20);
    $lineplot->value->show();
    $lineplot->value->SetColor('blue');
    $lineplot->value->SetFormat('%0.0f');
    $lineplot->SetLegend($_SESSION[Tahun1]);
    $lineplot2 = new LinePlot($data2);
    $lineplot2->SetColor("green");
    $lineplot2->SetWeight(2);
    $lineplot2->mark->SetType(MARK_FILLEDCIRCLE);
    $lineplot2->mark->SetWidth(3);
    $lineplot2->mark->SetFillColor('green');
    $lineplot2->value->show();
    $lineplot2->value->SetColor('darkgreen');
    $lineplot2->value->SetFormat('%0.0f');
    $lineplot2->SetLegend($_SESSION[Tahun2]);
    // Add the plot to the graph
    $graph->Add($lineplot);
    $graph->xaxis->SetTickLabels($datax);
    $graph->title->Set($title);
    $graph->xaxis->title->Set("");
    $graph->yaxis->title->Set("");
    $graph->title->SetFont(FF_FONT1, FS_BOLD);
    $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
    $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
    $graph->Add($lineplot2);
    $graph->legend->SetShadow(false);
    $graph->legend->SetFillColor('white');
    $graph->legend->SetPos(0.01, 0.88, 'right', 'center');
    // Display the graph
    $graph->Stroke($output);
}
Example #10
0
 public function drawGraph()
 {
     // generate graphic
     $graph = new Graph($this->width, $this->height, "auto");
     $graph->SetScale("textlin");
     // add shadow
     $graph->SetShadow();
     // change border
     $graph->img->SetMargin(40, 30, 20, 40);
     $graph->legend->Pos(0.05, 0.05, "right", "top");
     // generate bars
     $bplot = new BarPlot(array_values($this->dataPdf));
     $bplot->SetLegend($this->filesLabel);
     $bplot2 = new BarPlot(array_values($this->dataFrontdoor));
     $bplot2->SetLegend($this->frontdoorLabel);
     $gbplot = new GroupBarPlot(array($bplot, $bplot2));
     $graph->Add($gbplot);
     // format bars
     $bplot->SetFillColor('orange');
     $bplot->SetShadow();
     $bplot->SetFillGradient("orange", "yellow", GRAD_HOR);
     $bplot->value->Show();
     $bplot->value->SetFormat('%d');
     $bplot->value->SetFont(FF_FONT1, FS_BOLD);
     //$bplot->value->SetAngle(45);
     $bplot->value->SetColor("darkblue", "darkred");
     $bplot2->SetFillColor('blue');
     $bplot2->SetShadow();
     $bplot2->SetFillGradient("blue", "lightblue", GRAD_HOR);
     $bplot2->value->Show();
     $bplot2->value->SetFormat('%d');
     $bplot2->value->SetFont(FF_FONT1, FS_BOLD);
     //$bplot2->value->SetAngle(45);
     $bplot2->value->SetColor("darkgreen", "darkred");
     // format graphic
     $graph->title->Set($this->title);
     $graph->xaxis->title->Set($this->xaxis);
     $graph->yaxis->title->Set($this->yaxis);
     $graph->xaxis->SetTickLabels(array_keys($this->dataPdf));
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->scale->SetGrace(35);
     // show graphic
     $graph->Stroke();
 }
Example #11
0
File: image.php Project: ztobs/wsf
function draw_graph($datay, $data2y, $label_x)
{
    include_once "src/jpgraph.php";
    include_once "src/jpgraph_line.php";
    // A nice graph with anti-aliasing
    $graph = new Graph(800, 600, "auto");
    $graph->img->SetMargin(40, 180, 40, 40);
    $graph->img->SetAntiAliasing("white");
    $graph->SetScale("textlin");
    $graph->SetShadow();
    $graph->title->Set("Nodes and Comment Count By Duration");
    $graph->xaxis->SetTickLabels($label_x);
    // Use built in font
    $graph->title->SetFont(FF_FONT1, FS_BOLD);
    // Slightly adjust the legend from it's default position in the
    // top right corner.
    $graph->legend->Pos(0.05, 0.5, "right", "center");
    // Create the first line
    if ($datay) {
        $p1 = new LinePlot($datay);
        $p1->mark->SetType(MARK_FILLEDCIRCLE);
        $p1->mark->SetFillColor("blue");
        $p1->mark->SetWidth(4);
        $p1->SetColor("blue");
        $p1->SetCenter();
        $p1->SetLegend("Nodes Count");
        $graph->Add($p1);
    }
    // ... and the second
    if ($data2y) {
        $p2 = new LinePlot($data2y);
        $p2->mark->SetType(MARK_STAR);
        $p2->mark->SetFillColor("red");
        $p2->mark->SetWidth(4);
        $p2->SetColor("red");
        $p2->SetCenter();
        $p2->SetLegend("Comments Count");
        $graph->Add($p2);
    }
    // Output line
    $graph->Stroke();
}
Example #12
0
 function plot()
 {
     $this->_setValues();
     $graph = new Graph(380, 250);
     $graph->img->SetMargin(50, 30, 40, 40);
     $graph->SetShadow();
     $graph->SetColor("lightyellow");
     $graph->SetScale("textlin");
     $graph->title->Set($this->_graphTitle);
     $graph->yaxis->SetColor("blue");
     $graph->xaxis->SetColor("blue");
     $graph->title->SetFont(FONT1_BOLD);
     $graph->xaxis->SetTickLabels($this->_xaxisValues);
     $lineplot = new LinePlot($this->_yaxisValues);
     $lineplot->SetColor("red");
     // Add the plot to the graph
     $graph->Add($lineplot);
     // Display the graph
     $graph->Stroke();
 }
function generate_image()
{
    global $percent, $legend;
    // Create the graph. These two calls are always required
    $graph = new Graph(550, 250);
    $graph->SetScale("textlin");
    $graph->yaxis->scale->SetGrace(20);
    $graph->xaxis->SetLabelmargin(5);
    $graph->xaxis->SetTickLabels($legend);
    $graph->ygrid->SetFill(true, '#EFEFEF@0.5', '#BBCCFF@0.5');
    // Add a drop shadow
    $graph->SetShadow();
    // Adjust the margin a bit to make more room for titles
    $graph->img->SetMargin(50, 30, 20, 40);
    // Create a bar pot
    $bplot = new BarPlot($percent);
    // Adjust fill color
    $bplot->SetFillColor('#9999CC');
    $bplot->SetShadow();
    $bplot->value->Show();
    $bplot->value->SetFont(FF_ARIAL, FS_BOLD, 10);
    $bplot->value->SetAngle(45);
    $bplot->value->SetFormat('%0.0f');
    // Width
    $bplot->SetWidth(0.6);
    $graph->Add($bplot);
    // Setup the titles
    $graph->title->Set("PHP documentation");
    $graph->xaxis->title->Set("Language");
    $graph->yaxis->title->Set("Files up to date (%)");
    $graph->title->SetFont(FF_FONT1, FS_BOLD);
    $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
    $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
    // Display the graph
    $graph->Stroke('../www/images/revcheck/info_revcheck_php_all_lang.png');
}
Example #14
0
/**
 * Método que sirve de reemplazo al mecanismo de paloSantoGraph y paloSantoGraphLib
 * para generar gráficos a partir de una clase que devuelve datos.
 *
 * @param   string  $module     Módulo que contiene la clase fuente de datos
 * @param   string  $class      Clase a instanciar para obtener fuente de datos
 * @param   string  $function   Método a llamar en la clase para obtener datos
 * @param   array   $arrParameters  Lista de parámetros para la invocación 
 * @param   string  $functionCB 
 */
function displayGraph($G_MODULE, $G_CLASS, $G_FUNCTION, $G_PARAMETERS, $G_FUNCTIONCB = "")
{
    //------- PARAMETROS DEL GRAPH -------
    $G_TYPE = null;
    //tipo de grafica
    $G_TITLE = null;
    //titulo
    $G_COLOR = null;
    //colores
    $G_LABEL = array();
    //etiquetas
    $G_SIZE = array();
    //tamaño
    $G_MARGIN = array();
    //margen
    $G_LEYEND_NUM_COLUMN = 1;
    $G_LEYEND_POS = array(0.05, 0.5);
    //posicion de las leyendas
    $_MSJ_ERROR = null;
    //$_MSJ_ERROR   = "Sin mensaje ERROR";
    global $_MSJ_NOTHING;
    //$_MSJ_NOTHING = "Sin mensaje NOTHING";
    $G_YDATAS = array();
    $G_ARR_COLOR = array();
    $G_ARR_FILL_COLOR = array();
    $G_ARR_LEYEND = array();
    $G_ARR_STEP = array();
    $G_SHADOW = false;
    $G_LABEL_Y = null;
    //ESTATICOS
    $G_SCALE = "textlin";
    $G_WEIGHT = 1;
    if ($G_MODULE != '') {
        require_once "modules/{$G_MODULE}/libs/{$G_CLASS}.class.php";
        //lib del modulo
        require_once "modules/{$G_MODULE}/configs/default.conf.php";
        //archivo configuracion del modulo
        global $arrConfModule;
        $dsn = isset($arrConfModule["dsn_conn_database"]) ? $arrConfModule["dsn_conn_database"] : "";
    } else {
        require_once "libs/{$G_CLASS}.class.php";
        //lib del modulo
        require_once "configs/default.conf.php";
        //archivo configuracion del modulo
        global $arrConf;
        $dsn = isset($arrConf["dsn_conn_database"]) ? $arrConf["dsn_conn_database"] : "";
    }
    $oPaloClass = new $G_CLASS($dsn);
    $arrParam = $G_PARAMETERS;
    $result = call_user_func_array(array(&$oPaloClass, $G_FUNCTION), $arrParam);
    global $globalCB;
    $globalCB = NULL;
    if ($G_FUNCTIONCB != '') {
        $globalCB = array($oPaloClass, $G_FUNCTIONCB);
    }
    //------------------- CONTRUCCION DEL ARREGLO PARA X & Y -------------------
    global $xData;
    $xData = array();
    $yData = array();
    if (sizeof($result) != 0) {
        $isX_array = false;
        //usado en LINEPLOT, PLOT3D, BARPLOT, LINEPLOT_MULTIAXIS
        foreach ($result as $att => $arrXY) {
            //------------------ ATTRIBUTES ------------------
            if ($att == 'ATTRIBUTES') {
                foreach ($arrXY as $key => $values) {
                    //VARIABLES NECESARIAS
                    if ($key == 'LABEL_X') {
                        $G_LABEL[0] = $values;
                    } else {
                        if ($key == 'LABEL_Y') {
                            $G_LABEL[1] = $values;
                        } else {
                            if ($key == 'TITLE') {
                                $G_TITLE = $values;
                            } else {
                                if ($key == 'TYPE') {
                                    $G_TYPE = $values;
                                } else {
                                    if ($key == 'SIZE') {
                                        $G_SIZE = explode(',', $values);
                                    } else {
                                        if ($key == 'MARGIN') {
                                            $G_MARGIN = explode(',', $values);
                                        } else {
                                            if ($key == 'COLOR') {
                                                $G_COLOR = $values;
                                            } else {
                                                if ($key == 'POS_LEYEND') {
                                                    $G_LEYEND_POS = explode(',', $values);
                                                } else {
                                                    if ($key == 'NUM_COL_LEYEND') {
                                                        $G_LEYEND_NUM_COLUMN = $values;
                                                    } else {
                                                        if ($key == 'SHADOW') {
                                                            $G_SHADOW = $values;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if ($att == 'MESSAGES') {
                    foreach ($arrXY as $key => $values) {
                        if ($key == 'ERROR') {
                            $_MSJ_ERROR = $values;
                        } else {
                            if ($key == 'NOTHING_SHOW') {
                                $_MSJ_NOTHING = $values;
                            }
                        }
                    }
                } else {
                    if ($att == 'DATA') {
                        foreach ($arrXY as $DAT_N => $MODES) {
                            foreach ($MODES as $key => $values) {
                                /************************************************************/
                                if ($G_TYPE == 'lineplot' || $G_TYPE == 'barplot' || $G_TYPE == 'lineplot_multiaxis') {
                                    if ($key == 'VALUES') {
                                        $yData = array();
                                        foreach ($values as $x => $y) {
                                            if ($isX_array == false) {
                                                $xData[] = $x;
                                            }
                                            $yData[] = $y;
                                        }
                                        $isX_array = is_array($xData) ? true : false;
                                        $G_YDATAS[] = $yData;
                                    } else {
                                        if ($key == 'STYLE') {
                                            foreach ($values as $x => $y) {
                                                if ($x == 'COLOR') {
                                                    $G_ARR_COLOR[] = $y;
                                                } else {
                                                    if ($x == 'LEYEND') {
                                                        $G_ARR_LEYEND[] = $y;
                                                    } else {
                                                        if ($x == 'STYLE_STEP') {
                                                            $G_ARR_STEP[] = $y;
                                                        } else {
                                                            if ($x == 'FILL_COLOR') {
                                                                $G_ARR_FILL_COLOR[] = $y;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    if ($G_TYPE == 'plot3d' || $G_TYPE == 'plot3d2') {
                                        if ($key == 'VALUES') {
                                            foreach ($values as $x => $y) {
                                                $yData[] = $y;
                                            }
                                            $G_YDATAS[0] = $yData;
                                        } else {
                                            if ($key == 'STYLE') {
                                                foreach ($values as $x => $y) {
                                                    if ($x == 'COLOR') {
                                                        $G_ARR_COLOR[] = $y;
                                                    } else {
                                                        if ($x == 'LEYEND') {
                                                            $xData[] = $y;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                        if ($G_TYPE == 'bar' || $G_TYPE == 'gauge') {
                                            if ($key == 'VALUES') {
                                                foreach ($values as $x => $y) {
                                                    $G_YDATAS[] = $y;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //*****************************************//
    //      ***** ***** ***** ***** *   *      //
    //      *     *   * *   * *   * *   *      //
    //      * *** ***** ***** ***** *****      //
    //      *   * * *   *   * *     *   *      //
    //      ***** *   * *   * *     *   *      //
    //*****************************************//
    // L I N E P L O T
    if (sizeof($G_YDATAS) >= 1) {
        // true no funciona porque cada cadena u otro valor que se retorne es valor "valido o verdadero"
        // y equivale a true, entonces para diferenciarlo verdaderamente se compara con 'true'
        $str = checkAttributes($G_TITLE, $G_TYPE, $G_LABEL_Y, $_MSJ_ERROR, $_MSJ_NOTHING);
        if ($str != 'true') {
            showError($str, $G_SIZE);
            return;
        }
        if ($G_TYPE == 'lineplot') {
            $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
            if ($G_SHADOW) {
                $graph->SetShadow();
            }
            $graph->SetScale($G_SCALE);
            $graph->SetMarginColor($G_COLOR);
            $graph->title->Set($G_TITLE);
            $graph->SetFrame(true, '#999999');
            $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
            $graph->img->SetAntiAliasing();
            $graph->xaxis->SetLabelFormatCallback("CallBack");
            $graph->xaxis->SetLabelAngle(90);
            $graph->xaxis->title->Set($G_LABEL[0]);
            $graph->yaxis->title->Set($G_LABEL[1]);
            $graph->xgrid->Show();
            $graph->legend->SetFillColor("#fafafa");
            $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
            $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
            $graph->legend->SetColor("#444444", "#999999");
            $arr_lineplot = array();
            foreach ($G_YDATAS as $num => $yDatas) {
                $lineplot = new LinePlot($yDatas);
                if ($G_ARR_STEP[$num] == true) {
                    $lineplot->SetStepStyle();
                }
                if ($G_ARR_FILL_COLOR[$num] == true) {
                    $lineplot->SetFillColor($G_ARR_COLOR[$num]);
                }
                $lineplot->SetColor($G_ARR_COLOR[$num]);
                $lineplot->SetWeight($G_WEIGHT);
                $lineplot->SetLegend($G_ARR_LEYEND[$num]);
                $arr_lineplot[] = $lineplot;
            }
            foreach ($arr_lineplot as $num => $yDatas) {
                $graph->Add($yDatas);
            }
            if (sizeof($xData) > 100) {
                $graph->xaxis->SetTextTickInterval((int) (sizeof($xData) / 10));
            }
            $graph->Stroke();
        } else {
            if ($G_TYPE == 'plot3d') {
                $graph = new PieGraph($G_SIZE[0], $G_SIZE[1], "auto");
                if ($G_SHADOW) {
                    $graph->SetShadow();
                }
                $dataMarginColor = isset($result["ATTRIBUTES"]["MARGIN_COLOR"]) ? $result["ATTRIBUTES"]["MARGIN_COLOR"] : "#999999";
                $dataSizePie = isset($result["ATTRIBUTES"]["SIZE_PIE"]) ? $result["ATTRIBUTES"]["SIZE_PIE"] : "80";
                $graph->SetMarginColor($G_COLOR);
                $graph->SetFrame(true, $dataMarginColor);
                $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                $graph->legend->SetFillColor("#fafafa");
                $graph->legend->SetColor("#444444", "#999999");
                $graph->legend->SetShadow('gray@0.6', 4);
                $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                $graph->title->Set($G_TITLE);
                $pieplot3d = new PiePlot3d($G_YDATAS[0]);
                $pieplot3d->SetSliceColors($G_ARR_COLOR);
                $pieplot3d->SetCenter(0.4);
                $pieplot3d->SetSize($dataSizePie);
                $pieplot3d->SetAngle(45);
                $pieplot3d->SetStartAngle(45);
                $pieplot3d->value->SetColor('black');
                //color a los porcentages
                $pieplot3d->SetEdge('black');
                //da color al contorno y separacion del pastel
                $pieplot3d->SetLegends($xData);
                $graph->Add($pieplot3d);
                $graph->Stroke();
            } else {
                if ($G_TYPE == 'plot3d2') {
                    if (!function_exists('displayGraph_draw_pie3d')) {
                        function displayGraph_draw_pie3d($canvasx, $ydata, $arrcolor)
                        {
                            $canvasy = $canvasx;
                            $escala = $canvasx / 320.0;
                            $iAnchoPastel = 256 * $escala;
                            $iAltoPastel = 155 * $escala;
                            $iPosCentroX = 141 * $escala;
                            $iPosCentroY = 91 * $escala;
                            $thumb = imagecreatetruecolor($canvasx * 284 / 320, $canvasy * 250 / 320);
                            $transparent = imagecolorallocatealpha($thumb, 200, 200, 200, 127);
                            imagefill($thumb, 0, 0, $transparent);
                            // Asignar colores de imagen
                            $imgcolor = array();
                            foreach ($arrcolor as $i => $sHtmlColor) {
                                $r = $g = $b = 0;
                                sscanf($sHtmlColor, "#%02x%02x%02x", $r, $g, $b);
                                $imgcolor[$i] = imagecolorallocate($thumb, $r, $g, $b);
                            }
                            $colorTexto = imagecolorallocate($thumb, 0, 0, 0);
                            // Mostrar el gráfico de pastel
                            if (!function_exists('displayGraph_pie')) {
                                function displayGraph_pie($thumb, $x, $y, $w, $h, $ydata, $G_ARR_COLOR, $colorTexto)
                                {
                                    $iTotal = array_sum($ydata);
                                    $iFraccion = 0;
                                    $etiquetas = array();
                                    for ($i = 0; $i < count($ydata); $i++) {
                                        if ($ydata[$i] >= $iTotal) {
                                            imagefilledellipse($thumb, $x, $y, $w, $h, $G_ARR_COLOR[$i]);
                                        } else {
                                            $degInicio = 360 - 45 - (int) (360.0 * ($iFraccion + $ydata[$i]) / $iTotal);
                                            $degFinal = 360 - 45 - (int) (360.0 * $iFraccion / $iTotal);
                                            imagefilledarc($thumb, $x, $y, $w, $h, $degInicio, $degFinal, $G_ARR_COLOR[$i], IMG_ARC_PIE);
                                        }
                                        $iFraccion += $ydata[$i];
                                        $degMitad = ($degInicio + $degFinal) / 2;
                                        $iPosTextoX = $x + 0.5 * ($w / 2.0) * cos(deg2rad($degMitad));
                                        $iPosTextoY = $y + 0.5 * ($h / 2.0) * sin(deg2rad($degMitad));
                                        $etiquetas[] = array($iPosTextoX, $iPosTextoY, sprintf('%.1f %%', 100.0 * $ydata[$i] / $iTotal));
                                    }
                                    /*
                                                            if (!is_null($colorTexto)) {
                                                                for ($i = 0; $i < count($ydata); $i++)
                                                                    imagestring($thumb, 5, $etiquetas[$i][0], $etiquetas[$i][1], $etiquetas[$i][2], $colorTexto);
                                                            }
                                    */
                                }
                            }
                            for ($i = (int) (60 * $escala); $i > 0; $i--) {
                                displayGraph_pie($thumb, $iPosCentroX, $iPosCentroY + $i, $iAnchoPastel, $iAltoPastel, $ydata, $imgcolor, NULL);
                            }
                            displayGraph_pie($thumb, $iPosCentroX, $iPosCentroY, $iAnchoPastel, $iAltoPastel, $ydata, $imgcolor, $colorTexto);
                            imagealphablending($thumb, true);
                            imagesavealpha($thumb, true);
                            $source2 = imagecreatefrompng("images/pie_alpha.png");
                            imagealphablending($source2, true);
                            imagecopyresampled($thumb, $source2, 0, 0, 0, 0, 290 * $escala, 294 * $escala, 290, 294);
                            header("Content-Type: image/png");
                            imagepng($thumb);
                        }
                    }
                    displayGraph_draw_pie3d($G_SIZE[0], $G_YDATAS[0], $G_ARR_COLOR);
                } else {
                    if ($G_TYPE == 'barplot') {
                        $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
                        if ($G_SHADOW) {
                            $graph->SetShadow();
                        }
                        $graph->SetScale($G_SCALE);
                        $graph->SetMarginColor($G_COLOR);
                        $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
                        $graph->title->Set($G_TITLE);
                        $graph->xaxis->title->Set($G_LABEL[0]);
                        $graph->xaxis->SetLabelFormatCallback("CallBack");
                        $graph->xaxis->SetLabelAngle(90);
                        //$graph->xaxis->SetTickLabels($xData);
                        $graph->yaxis->title->Set($G_LABEL[1]);
                        $graph->legend->SetFillColor("#fafafa");
                        $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                        $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                        $arr_barplot = array();
                        foreach ($G_YDATAS as $num => $yDatas) {
                            $barplot = new BarPlot($yDatas);
                            $barplot->SetFillColor($G_ARR_COLOR[$num]);
                            $barplot->SetLegend($G_ARR_LEYEND[$num]);
                            $arr_barplot[] = $barplot;
                        }
                        $gbarplot = new GroupBarPlot($arr_barplot);
                        $gbarplot->SetWidth(0.6);
                        $graph->Add($gbarplot);
                        $graph->Stroke();
                    } else {
                        if ($G_TYPE == 'lineplot_multiaxis') {
                            $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
                            if ($G_SHADOW) {
                                $graph->SetShadow();
                            }
                            $inc = sizeof($G_YDATAS);
                            $graph->SetScale($G_SCALE);
                            $graph->SetFrame(true, '#999999');
                            $graph->title->Set($G_TITLE);
                            $graph->img->SetAntiAliasing();
                            $graph->xaxis->SetLabelFormatCallback("CallBack");
                            $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
                            $graph->SetMarginColor($G_COLOR);
                            $graph->legend->SetFillColor("#fafafa");
                            $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                            $graph->xaxis->SetLabelAngle(90);
                            $graph->legend->SetColor("#444444", "#999999");
                            $graph->legend->SetShadow('gray@0.6', 4);
                            $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                            foreach ($G_YDATAS as $num => $yData) {
                                $lineplot = new LinePlot($yData);
                                $lineplot->SetWeight($G_WEIGHT);
                                $lineplot->SetLegend($G_ARR_LEYEND[$num]);
                                if ($G_ARR_STEP[$num] == true) {
                                    $lineplot->SetStepStyle();
                                }
                                if ($G_ARR_FILL_COLOR[$num] == true) {
                                    $lineplot->SetFillColor($G_ARR_COLOR[$num]);
                                }
                                if ($num == 0) {
                                    $lineplot->SetColor($G_ARR_COLOR[$num]);
                                    $graph->yaxis->SetColor($G_ARR_COLOR[$num]);
                                    $graph->Add($lineplot);
                                } else {
                                    $lineplot->SetColor($G_ARR_COLOR[$num]);
                                    $graph->SetYScale($num - 1, 'lin');
                                    $graph->ynaxis[$num - 1]->SetColor($G_ARR_COLOR[$num]);
                                    $graph->ynaxis[$num - 1]->SetPosAbsDelta($G_MARGIN[1] + 49 * ($num - 1));
                                    //mueve el eje Y
                                    $graph->AddY($num - 1, $lineplot);
                                }
                            }
                            if (sizeof($xData) > 100) {
                                //$graph->xaxis->SetTextLabelInterval( (int)(sizeof($xData)/8) );
                                $graph->xaxis->SetTextTickInterval((int) (sizeof($xData) / 10));
                                //$graph->xaxis->SetTextTickInterval( 9*(int)(log(sizeof($xData))-1) );
                            }
                            $graph->Stroke();
                        } else {
                            if ($G_TYPE == 'bar') {
                                $g = new CanvasGraph(91, 21, 'auto');
                                $g->SetMargin(0, 0, 0, 0);
                                $g->InitFrame();
                                $xmax = 20;
                                $ymax = 20;
                                $scale = new CanvasScale($g);
                                $scale->Set(0, $G_SIZE[0], 0, $G_SIZE[1]);
                                //DUBUJA LA BARRA
                                $alto = $G_SIZE[1];
                                $ancho = $G_SIZE[0];
                                $coor_x = 0;
                                $coor_y = 0;
                                $porcentage = $G_YDATAS[0];
                                $valor = 90 * (1 - $porcentage);
                                $g->img->Line($coor_x, $coor_y, $coor_x + $ancho, $coor_y);
                                $g->img->Line($coor_x, $coor_y, $coor_x, $coor_y + $alto);
                                $g->img->Line($coor_x + $ancho, $coor_y, $coor_x + $ancho, $coor_y + $alto);
                                $g->img->Line($coor_x, $coor_y + $alto, $coor_x + $ancho, $coor_y + $alto);
                                for ($i = 0; $i < $alto; $i++) {
                                    $g->img->SetColor(array(95 - 3 * $i, 138 - 3 * $i, 203 - 3 * $i));
                                    //para hacerlo 3D, degradacion
                                    $g->img->Line($coor_x, $coor_y + $i + 1, $coor_x + $ancho - $valor - 1, $coor_y + $i + 1);
                                }
                                $g->Stroke();
                            } else {
                                if ($G_TYPE == 'gauge') {
                                    if (!function_exists('displayGraph_draw_gauge')) {
                                        function displayGraph_draw_gauge($canvasx, $percent)
                                        {
                                            $escala = $canvasx / 320.0;
                                            $thumb = imagecreatetruecolor($canvasx * 284 / 320, $canvasx * 284 / 320);
                                            if ($percent > 100) {
                                                $percent = 100.0;
                                            }
                                            if ($percent < 0) {
                                                $percent = 0.0;
                                            }
                                            $angle = -135.0 + 270 * $percent / 100.0;
                                            // COLORES
                                            $blanco = imagecolorallocate($thumb, 255, 255, 255);
                                            $dred = imagecolorallocate($thumb, 180, 0, 0);
                                            $lred = imagecolorallocate($thumb, 100, 0, 0);
                                            $transparent = imagecolorallocatealpha($thumb, 200, 200, 200, 127);
                                            imagefill($thumb, 0, 0, $transparent);
                                            imagealphablending($thumb, true);
                                            imagesavealpha($thumb, true);
                                            $source = imagecreatefrompng("images/gauge_base.png");
                                            imagealphablending($source, true);
                                            imagecopyresampled($thumb, $source, 0, 0, 0, 0, 285 * $escala, 285 * $escala, 285, 285);
                                            $radius = 100 * $escala;
                                            $radius_min = 12 * $escala;
                                            $centrox = 142 * $escala;
                                            $centroy = 141 * $escala;
                                            $x1 = $centrox + sin(deg2rad($angle)) * $radius;
                                            // x coord farest
                                            $x2 = $centrox + sin(deg2rad($angle - 90)) * $radius_min;
                                            $x3 = $centrox + sin(deg2rad($angle + 90)) * $radius_min;
                                            $y1 = $centroy - cos(deg2rad($angle)) * $radius;
                                            $y2 = $centroy - cos(deg2rad($angle - 90)) * $radius_min;
                                            $y3 = $centroy - cos(deg2rad($angle + 90)) * $radius_min;
                                            $arrTriangle1 = array($centrox, $centroy, $x1, $y1, $x2, $y2);
                                            $arrTriangle2 = array($centrox, $centroy, $x1, $y1, $x3, $y3);
                                            imagefilledpolygon($thumb, $arrTriangle1, 3, $lred);
                                            imagefilledpolygon($thumb, $arrTriangle2, 3, $dred);
                                            $source2 = imagecreatefrompng("images/gauge_center.png");
                                            imagealphablending($source2, true);
                                            imagecopyresampled($thumb, $source2, 121 * $escala, 120 * $escala, 0, 0, 44 * $escala, 44 * $escala, 44, 44);
                                            header("Content-Type: image/png");
                                            imagepng($thumb);
                                        }
                                    }
                                    displayGraph_draw_gauge($G_SIZE[0], $G_YDATAS[0] * 100.0);
                                } else {
                                    if ($G_TYPE == 'bar2') {
                                        $alto = 20;
                                        $ancho = 90;
                                        $coor_x = 100;
                                        $coor_y = 10;
                                        $porcentage = 0.67;
                                        $valor = 90 * (1 - $porcentage);
                                        $g = new CanvasGraph($G_LEN_X, 40, 'auto');
                                        $g->SetMargin(1, 1, 31, 9);
                                        $g->SetMarginColor('#fafafa');
                                        $g->SetColor(array(250, 250, 250));
                                        $g->InitFrame();
                                        $xmax = 20;
                                        $ymax = 20;
                                        $scale = new CanvasScale($g);
                                        $scale->Set(0, $G_LEN_X, 0, $G_LEN_Y);
                                        //DUBUJA LA BARRA
                                        $g->img->Line($coor_x, $coor_y, $coor_x + $ancho, $coor_y);
                                        $g->img->Line($coor_x, $coor_y, $coor_x, $coor_y + $alto);
                                        $g->img->Line($coor_x + $ancho, $coor_y, $coor_x + $ancho, $coor_y + $alto);
                                        $g->img->Line($coor_x, $coor_y + $alto, $coor_x + $ancho, $coor_y + $alto);
                                        for ($i = 0; $i < $alto; $i++) {
                                            $g->img->SetColor(array(95 - 4 * $i, 138 - 4 * $i, 203 - 4 * $i));
                                            //para hacerlo 3D, degradacion
                                            $g->img->Line($coor_x, $coor_y + $i, $coor_x + $ancho - $valor - 1, $coor_y + $i);
                                        }
                                        //AGREGA LABEL 1
                                        $txt = "Uso de CPU";
                                        $t = new Text($txt, 10, 12);
                                        $t->font_style = FS_BOLD;
                                        $t->Stroke($g->img);
                                        //AGREGA LABEL 2
                                        $txt = "67.64% used of 2,200.00 MHz";
                                        $t = new Text($txt, 200, 12);
                                        $t->font_style = FS_BOLD;
                                        $t->Stroke($g->img);
                                        $g->Stroke();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        showError('nothing', $G_SIZE, $G_TITLE);
    }
}
Example #15
0
 function generate_graph_image()
 {
     // Create the graph.
     // Set up Font Mapping Arrays
     $fontfamilies = array("Font 0" => FF_FONT0, "Font 1" => FF_FONT1, "Font 2" => FF_FONT2, "Font0" => FF_FONT0, "Font1" => FF_FONT1, "Font2" => FF_FONT2, "Arial" => FF_ARIAL, "Verdana" => FF_VERDANA, "Courier" => FF_COURIER, "Comic" => FF_COMIC, "Times" => FF_TIMES, "Georgia" => FF_GEORGIA, "Trebuchet" => FF_TREBUCHE, "advent_light" => advent_light, "Bedizen" => Bedizen, "Mukti_Narrow" => Mukti_Narrow, "calibri" => calibri, "Forgotte" => Forgotte, "GeosansLight" => GeosansLight, "MankSans" => MankSans, "pf_arma_five" => pf_arma_five, "Silkscreen" => Silkscreen, "verdana" => verdana, "Vera" => FF_VERA);
     $fontstyles = array("Normal" => FS_NORMAL, "Bold" => FS_BOLD, "Italic" => FS_ITALIC, "Bold+Italic" => FS_BOLDITALIC);
     $this->apply_defaults();
     if (!function_exists("imagecreatefromstring")) {
         handle_error("Graph Option Not Available. Requires GD2");
         return;
     }
     if ($this->plot[0]["type"] == "PIE" || $this->plot[0]["type"] == "PIE3D") {
         $graph = new PieGraph($this->width_actual, $this->height_actual, "auto");
         $graph->SetScale("textlin");
         $graph->img->SetMargin($this->marginleft_actual, $this->marginright_actual, $this->margintop_actual, $this->marginbottom_actual);
         $graph->SetMarginColor($this->margincolor_actual);
         $graph->img->SetAntiAliasing();
         $graph->SetColor($this->graphcolor_actual);
         $graph->SetShadow();
         $graph->xaxis->SetTitleMargin($this->marginbottom_actual - 45);
         $graph->yaxis->SetTitleMargin($this->marginleft_actual - 25);
     } else {
         $graph = new Graph($this->width_actual, $this->height_actual, "auto");
         $graph->SetScale("textlin");
         $graph->img->SetMargin($this->marginleft_actual, $this->marginright_actual, $this->margintop_actual, $this->marginbottom_actual);
         $graph->SetMarginColor($this->margincolor_actual);
         $graph->img->SetAntiAliasing();
         $graph->SetColor($this->graphcolor_actual);
         $graph->SetShadow();
         $graph->xaxis->SetTitleMargin($this->marginbottom_actual - 45);
         $graph->yaxis->SetTitleMargin($this->marginleft_actual - 25);
     }
     $lplot = array();
     $lplotct = 0;
     foreach ($this->plot as $k => $v) {
         switch ($v["type"]) {
             case "PIE":
                 $lplot[$lplotct] = new PiePlot($v["data"]);
                 $lplot[$lplotct]->SetColor($v["linecolor"]);
                 foreach ($xlabels as $k => $v) {
                     $xlabels[$k] = $v . "\n %.1f%%";
                 }
                 $lplot[$lplotct]->SetLabels($xlabels, 1.0);
                 $graph->Add($lplot[$lplotct]);
                 break;
             case "PIE3D":
                 $lplot[$lplotct] = new PiePlot3D($v["data"]);
                 $lplot[$lplotct]->SetColor($v["linecolor"]);
                 foreach ($xlabels as $k => $v) {
                     $xlabels[$k] = $v . "\n %.1f%%";
                 }
                 $lplot[$lplotct]->SetLabels($xlabels, 1.0);
                 $graph->Add($lplot[$lplotct]);
                 break;
             case "STACKEDBAR":
             case "BAR":
                 $lplot[$lplotct] = new BarPlot($v["data"]);
                 $lplot[$lplotct]->SetColor($v["linecolor"]);
                 $lplot[$lplotct]->SetWidth(0.8);
                 //$lplot[$lplotct]->SetWeight(5);
                 if ($v["fillcolor"]) {
                     $lplot[$lplotct]->SetFillColor($v["fillcolor"]);
                 }
                 if ($v["legend"]) {
                     $lplot[$lplotct]->SetLegend($v["legend"]);
                 }
                 $graph->Add($lplot[$lplotct]);
                 break;
             case "LINE":
             default:
                 if (count($v["data"]) == 1) {
                     $v["data"][] = 0;
                 }
                 $lplot[$lplotct] = new LinePlot($v["data"]);
                 $lplot[$lplotct]->SetColor($v["linecolor"]);
                 //$lplot[$lplotct]->SetWeight(5);
                 if ($v["fillcolor"]) {
                     $lplot[$lplotct]->SetFillColor($v["fillcolor"]);
                 }
                 if ($v["legend"]) {
                     $lplot[$lplotct]->SetLegend($v["legend"]);
                 }
                 $graph->Add($lplot[$lplotct]);
                 break;
         }
         $lplotct++;
     }
     $graph->title->Set($this->title_actual);
     $graph->xaxis->title->Set($this->xtitle_actual);
     $graph->yaxis->title->Set($this->ytitle_actual);
     $graph->xgrid->SetColor($this->xgridcolor_actual);
     $graph->ygrid->SetColor($this->ygridcolor_actual);
     switch ($this->xgriddisplay_actual) {
         case "all":
             $graph->xgrid->Show(true, true);
             break;
         case "major":
             $graph->xgrid->Show(true, false);
             break;
         case "minor":
             $graph->xgrid->Show(false, true);
             break;
         case "none":
         default:
             $graph->xgrid->Show(false, false);
             break;
     }
     switch ($this->ygriddisplay_actual) {
         case "all":
             $graph->ygrid->Show(true, true);
             break;
         case "major":
             $graph->ygrid->Show(true, false);
             break;
         case "minor":
             $graph->ygrid->Show(false, true);
             break;
         case "none":
         default:
             $graph->ygrid->Show(false, false);
             break;
     }
     $graph->title->SetFont($fontfamilies[$this->titlefont_actual], $fontstyles[$this->titlefontstyle_actual], $this->titlefontsize_actual);
     $graph->title->SetColor($this->titlecolor_actual);
     $graph->xaxis->SetFont($fontfamilies[$this->xaxisfont_actual], $fontstyles[$this->xaxisfontstyle_actual], $this->xaxisfontsize_actual);
     $graph->xaxis->SetColor($this->xaxiscolor_actual, $this->xaxisfontcolor_actual);
     $graph->yaxis->SetFont($fontfamilies[$this->yaxisfont_actual], $fontstyles[$this->yaxisfontstyle_actual], $this->yaxisfontsize_actual);
     $graph->yaxis->SetColor($this->yaxiscolor_actual, $this->yaxisfontcolor_actual);
     $graph->xaxis->title->SetFont($fontfamilies[$this->xtitlefont_actual], $fontstyles[$this->xtitlefontstyle_actual], $this->xtitlefontsize_actual);
     $graph->xaxis->title->SetColor($this->xtitlecolor_actual);
     $graph->yaxis->title->SetFont($fontfamilies[$this->ytitlefont_actual], $fontstyles[$this->ytitlefontstyle_actual], $this->ytitlefontsize_actual);
     $graph->yaxis->title->SetColor($this->ytitlecolor_actual);
     $graph->xaxis->SetLabelAngle(90);
     $graph->xaxis->SetLabelMargin(5);
     $graph->yaxis->SetLabelMargin(5);
     $graph->xaxis->SetTickLabels($this->xlabels);
     $graph->xaxis->SetTextLabelInterval($this->xticklabelinterval_actual);
     $graph->yaxis->SetTextLabelInterval($this->yticklabelinterval_actual);
     $graph->xaxis->SetTextTickInterval($this->xtickinterval_actual);
     $graph->yaxis->SetTextTickInterval($this->ytickinterval_actual);
     $graph->SetFrame(true, 'darkblue', 2);
     $graph->SetFrameBevel(2, true, 'black');
     if ($this->gridpos_actual == "front") {
         $graph->SetGridDepth(DEPTH_FRONT);
     }
     // Display the graph
     $handle = $graph->Stroke(_IMG_HANDLER);
     return $handle;
 }
Example #16
0
<?php

include "../jpgraph.php";
include "../jpgraph_line.php";
// create the graph
$graph = new Graph(400, 250, "auto");
$ydata = array(5, 10, 15, 20, 15, 10);
$graph->SetScale("textlin");
$graph->SetShadow(true);
$graph->SetMarginColor("antiquewhite");
$graph->img->SetMargin(60, 40, 40, 50);
$graph->img->setTransparent("white");
$graph->xaxis->SetFont(FF_FONT1);
$graph->xaxis->setTextTickInterval(1);
$graph->xaxis->SetTextLabelInterval(1);
$graph->legend->SetFillColor("antiquewhite");
$graph->legend->SetShadow(true);
$graph->legend->SetLayout(LEGEND_VERT);
$graph->legend->Pos(0.02, 0.01);
$graph->title->Set("Step Styled Example");
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$lineplot = new LinePlot($ydata);
$lineplot->SetColor("black");
$lineplot->setFillColor("gray7");
$lineplot->SetStepStyle();
$lineplot->SetLegend(" 2002 ");
// add plot to the graph
$graph->Add($lineplot);
$graph->ygrid->show(false, false);
// display graph
$graph->Stroke();
Example #17
0
 private function createBubbleGraph($datax, $datay, $dataz, $datalabel, $title)
 {
     global $format;
     // Create the graph.
     // We need to create X,Y data vectors suitable for the
     // library from the above raw data.
     $n = count($datax);
     for ($i = 0; $i < $n; ++$i) {
         // Create a faster lookup array so we don't have to search
         // for the correct values in the callback function
         $format[strval($datax[$i])][strval($datay[$i])] = array($datalabel[$i], $dataz[$i]);
     }
     // Callback for markers
     // Must return array(width,border_color,fill_color,filename,imgscale)
     // If any of the returned values are '' then the
     // default value for that parameter will be used (possible empty)
     function FCallback($aYVal, $aXVal)
     {
         global $format;
         return array($format[strval($aXVal)][strval($aYVal)][0], '', $format[strval($aXVal)][strval($aYVal)][1], '', '');
     }
     $graph = new Graph($this->width, $this->height, "auto");
     // Set the background image
     $graph->SetBackgroundImage('protected/lib/jpgraph/gfx/riscmap.jpg', BGIMG_COPY);
     $graph->SetScale("linlin");
     $graph->img->SetMargin(60, 60, 60, 60);
     $graph->title->Set($title);
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     if ($this->shadow) {
         $graph->SetShadow();
     }
     // Use a lot of grace to get large scales since the ballon have
     // size and we don't want them to collide with the X-axis
     $graph->yaxis->scale->SetGrace(50, 10);
     $graph->yaxis->title->Set($this->ylabel[0]);
     $graph->xaxis->scale->SetGrace(50, 10);
     $graph->xaxis->title->Set($this->xlabel[0]);
     // Make sure X-axis as at the bottom of the graph and not at the default Y=0
     $graph->xaxis->SetPos('min');
     // Set X-scale to start at 0
     $graph->xscale->SetAutoMin('min');
     // Create the scatter plot
     $sp1 = new ScatterPlot($datay, $datax);
     $sp1->mark->SetType(MARK_FILLEDCIRCLE);
     // Uncomment the following two lines to display the values
     $sp1->value->Show();
     $sp1->value->SetFont(FF_FONT1, FS_BOLD);
     // Callback for markers
     $sp1->mark->SetCallbackYX("FCallback");
     // Add the scatter plot to the graph
     $graph->Add($sp1);
     return $graph;
 }
Example #18
0
function print_graph($g, $pgwidth)
{
    $splines = false;
    $bandw = false;
    $percent = false;
    $show_percent = false;
    $stacked = false;
    $h = false;
    $show_values = false;
    $hide_grid = false;
    $hide_y_axis = false;
    if (isset($g['attr']['TYPE']) && $g['attr']['TYPE']) {
        $type = strtolower($g['attr']['TYPE']);
    }
    if (!in_array($type, array('bar', 'horiz_bar', 'line', 'radar', 'pie', 'pie3d', 'xy', 'scatter'))) {
        $type = 'bar';
    }
    // Default=bar
    if (isset($g['attr']['STACKED']) && $g['attr']['STACKED']) {
        $stacked = true;
    }
    // stacked for bar or horiz_bar
    if (isset($g['attr']['SPLINES']) && $g['attr']['SPLINES'] && $type == 'xy') {
        $splines = true;
    }
    // splines for XY line graphs
    if (isset($g['attr']['BANDW']) && $g['attr']['BANDW']) {
        $bandw = true;
    }
    // black and white
    if (isset($g['attr']['LEGEND-OVERLAP']) && $g['attr']['LEGEND-OVERLAP']) {
        $overlap = true;
    }
    // avoid overlap of Legends over graph (line, bar, horiz_bar only)
    if (isset($g['attr']['PERCENT']) && $g['attr']['PERCENT'] && $type != 'xy' && $type != 'scatter') {
        $percent = true;
    }
    // Show data series as percent of total in series
    if (isset($g['attr']['SHOW-VALUES']) && $g['attr']['SHOW-VALUES']) {
        $show_values = true;
    }
    // Show the individual data values
    if (isset($g['attr']['HIDE-GRID']) && $g['attr']['HIDE-GRID']) {
        $hide_grid = true;
    }
    // Hide the y-axis gridlines
    if (isset($g['attr']['HIDE-Y-AXIS']) && $g['attr']['HIDE-Y-AXIS']) {
        $hide_y_axis = true;
    }
    // Hide the y-axis
    // Antialias: If true - better quality curves, but graph line will only be 1px even in PDF 300dpi
    // default=true for most except line and radar
    if (isset($g['attr']['ANTIALIAS']) && ($g['attr']['ANTIALIAS'] == '' || $g['attr']['ANTIALIAS'] == 0)) {
        $antialias = false;
    } else {
        if (isset($g['attr']['ANTIALIAS']) && $g['attr']['ANTIALIAS'] > 0) {
            $antialias = true;
        } else {
            if ($type == 'line' || $type == 'radar') {
                $antialias = false;
            } else {
                $antialias = true;
            }
        }
    }
    if ($g['attr']['DPI']) {
        $dpi = intval($g['attr']['DPI']);
    }
    if (!$dpi || $dpi < 50 || $dpi > 2400) {
        $dpi = 150;
    }
    // Default dpi 150
    $k = 0.2645 / 25.4 * $dpi;
    // mPDF 4.5.009
    global $JpgUseSVGFormat;
    if (isset($JpgUseSVGFormat) && $JpgUseSVGFormat) {
        $img_type = 'svg';
        $k = 1;
        // Overrides as Vector scale does not need DPI
    } else {
        $img_type = 'png';
    }
    if (isset($g['attr']['TITLE']) && $g['attr']['TITLE']) {
        $title = $g['attr']['TITLE'];
    }
    if (isset($g['attr']['LABEL-X']) && $g['attr']['LABEL-X']) {
        $xlabel = $g['attr']['LABEL-X'];
    }
    // NOT IMPLEMENTED??????
    if (isset($g['attr']['LABEL-Y']) && $g['attr']['LABEL-Y']) {
        $ylabel = $g['attr']['LABEL-Y'];
    }
    if (isset($g['attr']['AXIS-X']) && $g['attr']['AXIS-X']) {
        $xaxis = strtolower($g['attr']['AXIS-X']);
    }
    if (!in_array($xaxis, array('text', 'lin', 'linear', 'log'))) {
        $xaxis = 'text';
    }
    // Default=text
    if ($xaxis == 'linear') {
        $xaxis = 'lin';
    }
    if (isset($g['attr']['AXIS-Y']) && $g['attr']['AXIS-Y']) {
        $yaxis = strtolower($g['attr']['AXIS-Y']);
    }
    if (!in_array($yaxis, array('lin', 'linear', 'log', 'percent'))) {
        $yaxis = 'lin';
    }
    // Default=lin
    if ($yaxis == 'percent') {
        $show_percent = true;
        $yaxis = 'lin';
    }
    // Show percent sign on scales
    if ($yaxis == 'linear') {
        $yaxis = 'lin';
    }
    if ($splines) {
        $xaxis = 'lin';
    }
    $axes = $xaxis . $yaxis;
    // e.g.textlin, textlog, loglog, loglin, linlog (XY)
    // mPDF 4.0
    if (isset($g['attr']['cWIDTH']) && $g['attr']['cWIDTH']) {
        $w = $g['attr']['cWIDTH'] / 0.2645;
    }
    // pixels
    if (isset($g['attr']['cHEIGHT']) && $g['attr']['cHEIGHT']) {
        $h = $g['attr']['cHEIGHT'] / 0.2645;
    }
    if (isset($g['attr']['SERIES']) && strtolower($g['attr']['SERIES']) == 'rows') {
        $dataseries = 'rows';
    } else {
        $dataseries = 'cols';
    }
    // Defaults - define data
    $rowbegin = 2;
    $colbegin = 2;
    if ($type == 'scatter' || $type == 'xy') {
        if ($dataseries == 'rows') {
            $rowbegin = 1;
        } else {
            $colbegin = 1;
        }
    }
    $rowend = 0;
    $colend = 0;
    if (isset($g['attr']['DATA-ROW-BEGIN']) && ($g['attr']['DATA-ROW-BEGIN'] === '0' || $g['attr']['DATA-ROW-BEGIN'] > 0)) {
        $rowbegin = $g['attr']['DATA-ROW-BEGIN'];
    }
    if (isset($g['attr']['DATA-COL-BEGIN']) && ($g['attr']['DATA-COL-BEGIN'] === '0' || $g['attr']['DATA-COL-BEGIN'] > 0)) {
        $colbegin = $g['attr']['DATA-COL-BEGIN'];
    }
    if (isset($g['attr']['DATA-ROW-END']) && ($g['attr']['DATA-ROW-END'] === '0' || $g['attr']['DATA-ROW-END'] != 0)) {
        $rowend = $g['attr']['DATA-ROW-END'];
    }
    if (isset($g['attr']['DATA-COL-END']) && ($g['attr']['DATA-COL-END'] === '0' || $g['attr']['DATA-COL-END'] != 0)) {
        $colend = $g['attr']['DATA-COL-END'];
    }
    $nr = count($g['data']);
    $nc = 0;
    foreach ($g['data'] as $r) {
        $cc = 0;
        foreach ($r as $c) {
            $cc++;
        }
        $nc = max($nc, $cc);
    }
    if ($colend == 0) {
        $colend = $nc;
    } else {
        if ($colend < 0) {
            $colend = $nc + $colend;
        }
    }
    if ($rowend == 0) {
        $rowend = $nr;
    } else {
        if ($rowend < 0) {
            $rowend = $nr + $rowend;
        }
    }
    if ($colend < $colbegin) {
        $colend = $colbegin;
    }
    if ($rowend < $rowbegin) {
        $rowend = $rowbegin;
    }
    //	if ($type == 'xy' || $type=='scatter') { $colstart=0; }
    // Get Data + Totals
    $data = array();
    $totals = array();
    for ($r = $rowbegin - 1; $r < $rowend; $r++) {
        for ($c = $colbegin - 1; $c < $colend; $c++) {
            if (isset($g['data'][$r][$c])) {
                $g['data'][$r][$c] = floatval($g['data'][$r][$c]);
            } else {
                $g['data'][$r][$c] = 0;
            }
            if ($dataseries == 'rows') {
                $data[$r + 1 - $rowbegin][$c + 1 - $colbegin] = $g['data'][$r][$c];
                $totals[$r + 1 - $rowbegin] += $g['data'][$r][$c];
            } else {
                $data[$c + 1 - $colbegin][$r + 1 - $rowbegin] = $g['data'][$r][$c];
                if (isset($totals[$c + 1 - $colbegin])) {
                    $totals[$c + 1 - $colbegin] += $g['data'][$r][$c];
                } else {
                    $totals[$c + 1 - $colbegin] = $g['data'][$r][$c];
                }
            }
        }
    }
    // PERCENT
    if ($percent && $type != 'pie' && $type != 'pie3d') {
        for ($r = 0; $r < count($data); $r++) {
            for ($c = 0; $c < count($data[$r]); $c++) {
                $data[$r][$c] = $data[$r][$c] / $totals[$r] * 100;
            }
        }
    }
    // Get Legends and labels
    $legends = array();
    $labels = array();
    $longestlegend = 0;
    $longestlabel = 0;
    if ($dataseries == 'cols') {
        if ($colbegin > 1) {
            for ($r = $rowbegin - 1; $r < $rowend; $r++) {
                $legends[$r + 1 - $rowbegin] = $g['data'][$r][0];
                $longestlegend = max($longestlegend, strlen($g['data'][$r][0]));
            }
        }
        if ($rowbegin > 1) {
            for ($c = $colbegin - 1; $c < $colend; $c++) {
                $labels[$c + 1 - $colbegin] = $g['data'][0][$c];
                $longestlabel = max($longestlabel, strlen($g['data'][0][$c]));
            }
        }
    } else {
        if ($dataseries == 'rows') {
            if ($colbegin > 1) {
                for ($r = $rowbegin - 1; $r < $rowend; $r++) {
                    $labels[$r + 1 - $rowbegin] = $g['data'][$r][0];
                    $longestlabel = max($longestlabel, strlen($g['data'][$r][0]));
                }
            }
            if ($rowbegin > 1) {
                for ($c = $colbegin - 1; $c < $colend; $c++) {
                    $legends[$c + 1 - $colbegin] = $g['data'][0][$c];
                    $longestlegend = max($longestlegend, strlen($g['data'][0][$c]));
                }
            }
        }
    }
    // Default sizes
    $defsize = array();
    $defsize['pie'] = array('w' => 600, 'h' => 300);
    $defsize['pie3d'] = array('w' => 600, 'h' => 300);
    $defsize['radar'] = array('w' => 600, 'h' => 300);
    $defsize['line'] = array('w' => 600, 'h' => 400);
    $defsize['xy'] = array('w' => 600, 'h' => 400);
    $defsize['scatter'] = array('w' => 600, 'h' => 400);
    $defsize['bar'] = array('w' => 600, 'h' => 400);
    $defsize['horiz_bar'] = array('w' => 600, 'h' => 500);
    // Use default ratios
    if ($w && !$h) {
        $h = $w * $defsize[$type]['h'] / $defsize[$type]['w'];
    }
    if ($h && !$w) {
        $w = $h * $defsize[$type]['w'] / $defsize[$type]['h'];
    }
    if (!$h && !$w) {
        $w = $defsize[$type]['w'];
        $h = $defsize[$type]['h'];
    }
    if (count($data) > 0 && $type) {
        $figure_file = "graph_cache/" . rand(11111, 999999999) . "." . $img_type;
        if ($bandw) {
            $colours = array('snow1', 'black', 'snow4', 'snow3', 'snow2', 'cadetblue4', 'cadetblue3', 'cadetblue1', 'bisque4', 'bisque2', 'beige');
        } else {
            $colours = array('cyan', 'darkorchid4', 'cadetblue3', 'khaki1', 'darkolivegreen2', 'cadetblue4', 'coral', 'cyan4', 'rosybrown3', 'wheat1');
        }
        $fills = array('navy', 'orange', 'red', 'yellow', 'purple', 'navy', 'orange', 'red', 'yellow', 'purple');
        $patterns = array(PATTERN_DIAG1, PATTERN_CROSS1, PATTERN_STRIPE1, PATTERN_DIAG3, PATTERN_CROSS2, PATTERN_DIAG2, PATTERN_DIAG4, PATTERN_CROSS3, PATTERN_CROSS4, PATTERN_STRIPE1);
        $markers = array(MARK_DIAMOND, MARK_SQUARE, MARK_CIRCLE, MARK_UTRIANGLE, MARK_DTRIANGLE, MARK_FILLEDCIRCLE, MARK_CROSS, MARK_STAR, MARK_X);
        // LEGENDS
        if ($type == 'pie' || $type == 'pie3d') {
            $graph = new PieGraph($w * $k, $h * $k);
        } else {
            if ($type == 'radar') {
                $graph = new RadarGraph($w * $k, $h * $k);
            } else {
                $graph = new Graph($w * $k, $h * $k);
            }
        }
        // mPDF 4.5.009
        //	$graph->img->SetImgFormat($img_type) ;
        //	if (strtoupper($img_type)=='JPEG') { $graph->img->SetQuality(90); }
        if ($antialias) {
            $graph->img->SetAntiAliasing();
        }
        $graph->SetShadow(true, 2 * $k);
        $graph->SetMarginColor("white");
        // TITLE
        $graph->title->Set($title);
        $graph->title->SetMargin(10 * $k);
        $graph->title->SetFont(FF_USERFONT, FS_BOLD, 11 * $k);
        $graph->title->SetColor("black");
        $graph->legend->SetLineSpacing(3 * $k);
        $graph->legend->SetMarkAbsSize(6 * $k);
        $graph->legend->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
        // Set GRAPH IMAGE MARGINS
        if ($type == 'pie' || $type == 'pie3d') {
            $psize = 0.3;
            $pposxabs = $w / 2;
            $pposy = 0.55;
            if ($longestlegend) {
                // if legend showing
                $pposxabs -= ($longestlegend * 5 + 20) / 2;
            }
            $pposx = $pposxabs / $w;
            $graph->legend->Pos(0.02, 0.5, 'right', 'center');
        } else {
            if ($type == 'radar') {
                $psize = 0.5;
                $pposxabs = $w / 2;
                $pposy = 0.55;
                if ($longestlabel) {
                    // if legend showing
                    $pposxabs -= ($longestlabel * 5 + 20) / 2;
                }
                $pposx = $pposxabs / $w;
                $graph->legend->Pos(0.02, 0.5, 'right', 'center');
            } else {
                if ($type == 'xy' || $type == 'scatter') {
                    $pml = 50;
                    $pmr = 20;
                    $pmt = 60;
                    $pmb = 50;
                    $xaxislblmargin = $pmb - 30;
                    $yaxislblmargin = $pml - 15;
                    $graph->legend->Pos(0.02, 0.1, 'right', 'top');
                } else {
                    if ($type == 'line' || $type == 'bar') {
                        $pml = 50;
                        $pmr = 20;
                        $pmt = 60;
                        $pmb = 50;
                        $xlangle = 0;
                        $ll = $longestlegend * 5;
                        // 45 degrees 8pt fontsize
                        if ($ll > 5 || $ll > 3 && count($data) > 10) {
                            $pmb = max($pmb, $ll + 30);
                            $xlangle = 50;
                        }
                        $xaxislblmargin = $pmb - 30;
                        $yaxislblmargin = $pml - 15;
                        if ($longestlabel && !$overlap) {
                            // if legend showing
                            $pmr = $longestlabel * 5 + 40;
                        }
                        $graph->legend->Pos(0.02, 0.1, 'right', 'top');
                    } else {
                        if ($type == 'horiz_bar') {
                            $pml = 50;
                            $pmr = 20;
                            $pmt = 50;
                            $pmb = 45;
                            $ll = $longestlegend * 6.5;
                            // 8pt fontsize
                            $pml = max($pml, $ll + 20);
                            $xaxislblmargin = $pml - 20;
                            $yaxislblmargin = $pmb - 15;
                            if ($longestlabel && !$overlap) {
                                // if legend showing
                                $pmr = $longestlabel * 5 + 40;
                            }
                            $graph->legend->Pos(0.02, 0.1, 'right', 'top');
                        }
                    }
                }
            }
        }
        // DRAW THE GRAPHS
        if ($type == 'pie') {
            $p1 = new PiePlot($data[0]);
            $p1->SetSliceColors($colours);
            if ($show_values) {
                $p1->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                if ($percent) {
                    $p1->SetLabelType(PIE_VALUE_PERADJ);
                } else {
                    $p1->SetLabelType(PIE_VALUE_ABS);
                }
                if ($percent || $show_percent) {
                    $p1->value->SetFormat("%d%%");
                } else {
                    $p1->value->SetFormat("%s");
                }
                // Enable and set policy for guide-lines. Make labels line up vertically
                $p1->SetGuideLines(true);
                $p1->SetGuideLinesAdjust(1.5);
            } else {
                $p1->value->Show(false);
            }
            $p1->SetLegends($legends);
            $p1->SetSize($psize);
            $p1->SetCenter($pposx, $pposy);
            if ($labels[0]) {
                $graph->subtitle->Set($labels[0]);
                $graph->subtitle->SetMargin(10 * $k);
                $graph->subtitle->SetFont(FF_USERFONT, FS_BOLD, 11 * $k);
                $graph->subtitle->SetColor("black");
            }
            $graph->Add($p1);
        } else {
            if ($type == 'pie3d') {
                $p1 = new PiePlot3d($data[0]);
                $p1->SetSliceColors($colours);
                if ($show_values) {
                    $p1->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                    if ($percent) {
                        $p1->SetLabelType(PIE_VALUE_PERADJ);
                    } else {
                        $p1->SetLabelType(PIE_VALUE_ABS);
                    }
                    if ($percent || $show_percent) {
                        $p1->value->SetFormat("%d%%");
                    } else {
                        $p1->value->SetFormat("%s");
                    }
                } else {
                    $p1->value->Show(false);
                }
                $p1->SetLegends($legends);
                $p1->SetEdge();
                $p1->SetSize($psize);
                $p1->SetCenter($pposx, $pposy);
                if ($labels[0]) {
                    $graph->subtitle->Set($labels[0]);
                    $graph->subtitle->SetMargin(10 * $k);
                    $graph->subtitle->SetFont(FF_USERFONT, FS_BOLD, 11 * $k);
                    $graph->subtitle->SetColor("black");
                }
                $graph->Add($p1);
            } else {
                if ($type == 'radar') {
                    $graph->SetSize($psize);
                    $graph->SetPos($pposx, $pposy);
                    $graph->SetTitles($legends);
                    // labels each axis
                    $graph->axis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                    $graph->axis->title->SetMargin(5 * $k);
                    $graph->axis->SetWeight(1 * $k);
                    $graph->axis->HideLabels();
                    $graph->axis->SetFont(FF_USERFONT, FS_NORMAL, 6 * $k);
                    $graph->HideTickMarks();
                    $group = array();
                    foreach ($data as $series => $dat) {
                        $rdata = array();
                        foreach ($data[$series] as $row) {
                            $rdata[] = $row;
                        }
                        if (count($rdata) < 3) {
                            die("ERROR::Graph::Cannot create a Radar Plot with less than 3 data points.");
                        }
                        // Create the radar plot
                        $bplot = new RadarPlot($rdata);
                        $bplot->mark->SetType($markers[$series]);
                        $bplot->mark->SetFillColor($colours[$series]);
                        $bplot->mark->SetWidth(3 * $k);
                        $bplot->SetColor($colours[$series]);
                        if ($series == 0) {
                            $bplot->SetFillColor('lightred');
                        } else {
                            $bplot->SetFill(false);
                        }
                        $bplot->SetLineWeight(1 * $k);
                        $bplot->SetLegend($labels[$series]);
                        if ($bandw) {
                            $bplot->SetShadow("gray5");
                        }
                        $graph->Add($bplot);
                    }
                } else {
                    if ($type == 'line') {
                        // Setup the graph.
                        $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k);
                        // LRTB
                        $graph->SetScale($axes);
                        $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                        if ($ylabel) {
                            $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                            $graph->yaxis->SetTitle($ylabel, 'middle');
                            $graph->yaxis->SetTitleMargin($yaxislblmargin * $k);
                        }
                        $graph->yaxis->SetLabelMargin(4 * $k);
                        if ($percent || $show_percent) {
                            $graph->yaxis->SetLabelFormat('%d%%');
                        }
                        // Percent
                        // Show 0 label on Y-axis (default is not to show)
                        $graph->yscale->ticks->SupressZeroLabel(true);
                        if ($hide_y_axis) {
                            $graph->yaxis->Hide();
                        }
                        if ($hide_grid) {
                            $graph->ygrid->Show(false);
                        }
                        // Setup X-axis labels
                        $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                        $graph->xaxis->SetTickLabels($legends);
                        $graph->xaxis->SetLabelAngle($xlangle);
                        $graph->xaxis->SetLabelMargin(4 * $k);
                        // X-axis title
                        if ($xlabel) {
                            $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                            $graph->xaxis->SetTitle($xlabel, 'middle');
                            $graph->xaxis->SetTitleMargin($xaxislblmargin * $k);
                        }
                        foreach ($data as $series => $rdata) {
                            $bplot = new LinePlot($rdata);
                            $bplot->mark->SetType($markers[$series]);
                            $bplot->mark->SetFillColor($colours[$series]);
                            $bplot->mark->SetWidth(4 * $k);
                            if ($show_values) {
                                $bplot->value->Show();
                                // Not if scatter
                                $bplot->value->SetMargin(6 * $k);
                                $bplot->value->SetColor("darkred");
                                $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                if ($percent || $show_percent) {
                                    $bplot->value->SetFormat('%d%%');
                                } else {
                                    $bplot->value->SetFormat("%s");
                                }
                            }
                            // Set color for each line
                            $bplot->SetColor($colours[$series]);
                            $bplot->SetWeight(2 * $k);
                            $bplot->SetLegend($labels[$series]);
                            if ($bandw) {
                                $bplot->SetShadow("gray5");
                            }
                            // Indent the X-scale so the first and last point doesn't fall on the edges
                            $bplot->SetCenter();
                            $graph->Add($bplot);
                        }
                    } else {
                        if ($type == 'xy' || $type == 'scatter') {
                            // Setup the graph.
                            $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k);
                            // LRTB
                            $graph->SetScale($axes);
                            // Setup font for axis
                            $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                            // Y-axis title
                            if ($labels[1]) {
                                $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                $graph->yaxis->SetTitleMargin($yaxislblmargin * $k);
                                $graph->yaxis->SetTitle($labels[1], 'middle');
                            }
                            $graph->yaxis->SetLabelMargin(4 * $k);
                            if ($percent || $show_percent) {
                                $graph->yaxis->SetLabelFormat('%d%%');
                            }
                            // Percent
                            // Show 0 label on Y-axis (default is not to show)
                            $graph->yscale->ticks->SupressZeroLabel(true);
                            // Just let the maximum be autoscaled
                            $graph->yaxis->scale->SetAutoMin(0);
                            if ($hide_y_axis) {
                                $graph->yaxis->Hide();
                            }
                            if ($hide_grid) {
                                $graph->ygrid->Show(false);
                            }
                            // Setup X-axis labels
                            $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                            // mPDF 2.5 Corrects labelling of x-axis
                            //			$graph->xaxis->SetTickLabels($legends);
                            $graph->xaxis->SetLabelAngle(50);
                            $graph->xaxis->SetLabelMargin(4 * $k);
                            // X-axis title
                            if ($labels[0]) {
                                $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                $graph->xaxis->SetTitleMargin($xaxislblmargin * $k);
                                $graph->xaxis->SetTitle($labels[0], 'middle');
                            }
                            // Create the bar plot
                            // SPLINES
                            if ($splines && $type == 'xy') {
                                $spline = new Spline($data[0], $data[1]);
                                list($newx, $newy) = $spline->Get(100);
                            } else {
                                $newx = $data[0];
                                $newy = $data[1];
                            }
                            if ($type == 'xy') {
                                // LINE PLOT
                                $bplot = new LinePlot($newy, $newx);
                                // Set color for each line
                                $bplot->SetColor($fills[0]);
                                $bplot->SetWeight(4 * $k);
                                if ($bandw) {
                                    $bplot->SetShadow("gray5");
                                }
                                $graph->Add($bplot);
                            }
                            // SCATTER PLOT
                            $cplot = new ScatterPlot($data[1], $data[0]);
                            $cplot->mark->SetType($markers[0]);
                            $cplot->mark->SetFillColor($fills[0]);
                            $cplot->mark->SetWidth(8 * $k);
                            if ($show_values) {
                                // mPDF 2.5
                                if ($type == 'xy') {
                                    $cplot->value->Show();
                                }
                                // Not if scatter
                                $cplot->value->SetMargin(8 * $k);
                                $cplot->value->SetColor("darkred");
                                $cplot->value->SetFont(FF_USERFONT, FS_NORMAL, 6 * $k);
                                if ($percent || $show_percent) {
                                    $cplot->value->SetFormat('%d%%');
                                } else {
                                    $cplot->value->SetFormat("%s");
                                }
                            }
                            // Set color for each line
                            $cplot->SetColor($fills[0]);
                            $cplot->SetWeight(4 * $k);
                            if ($bandw) {
                                $cplot->SetShadow("gray5");
                            }
                            $graph->Add($cplot);
                        } else {
                            if ($type == 'bar') {
                                // Setup the graph.
                                $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k);
                                // LRTB
                                $graph->SetScale($axes);
                                // Setup y-axis
                                $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                if ($hide_y_axis) {
                                    $graph->yaxis->Hide();
                                }
                                if ($hide_grid) {
                                    $graph->ygrid->Show(false);
                                }
                                $graph->yaxis->SetLabelMargin(4 * $k);
                                if ($ylabel) {
                                    $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                    $graph->yaxis->SetTitle($ylabel, 'middle');
                                    $graph->yaxis->SetTitleMargin($yaxislblmargin * $k);
                                }
                                // Show 0 label on Y-axis (default is not to show)
                                $graph->yscale->ticks->SupressZeroLabel(false);
                                // Setup X-axis labels
                                $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                $graph->xaxis->SetTickLabels($legends);
                                $graph->xaxis->SetLabelAngle($xlangle);
                                $graph->xaxis->SetLabelMargin(4 * $k);
                                // X-axis title
                                if ($xlabel) {
                                    $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                    $graph->xaxis->SetTitle($xlabel, 'middle');
                                    $graph->xaxis->SetTitleMargin($xaxislblmargin * $k);
                                }
                                $group = array();
                                foreach ($data as $series => $dat) {
                                    $rdata = array();
                                    foreach ($data[$series] as $row) {
                                        $rdata[] = $row;
                                    }
                                    // Create the bar plot
                                    $bplot = new BarPlot($rdata);
                                    $bplot->SetWidth(0.6);
                                    // for SINGLE??
                                    // Setup color for gradient fill style
                                    if ($bandw) {
                                        $bplot->SetPattern($patterns[$series]);
                                    } else {
                                        $bplot->SetFillGradient($fills[$series], "#EEEEEE", GRAD_LEFT_REFLECTION);
                                    }
                                    // Set color for the frame of each bar
                                    $bplot->SetColor("darkgray");
                                    $bplot->SetLegend($labels[$series]);
                                    if ($bandw) {
                                        $bplot->SetShadow("gray5");
                                    }
                                    if ($show_values) {
                                        $bplot->value->Show();
                                        $bplot->value->SetMargin(6 * $k);
                                        $bplot->value->SetColor("darkred");
                                        $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                        if ($percent || $show_percent) {
                                            $bplot->value->SetFormat('%d%%');
                                        } else {
                                            $bplot->value->SetFormat("%s");
                                        }
                                    }
                                    $group[] = $bplot;
                                }
                                if (count($data) == 1) {
                                    $graph->Add($group[0]);
                                } else {
                                    // Create the grouped bar plot
                                    if ($stacked) {
                                        $gbplot = new AccBarPlot($group);
                                    } else {
                                        $gbplot = new GroupBarPlot($group);
                                    }
                                    $graph->Add($gbplot);
                                }
                            } else {
                                if ($type == 'horiz_bar') {
                                    $graph->SetScale($axes);
                                    $graph->Set90AndMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k);
                                    // LRTB
                                    // Setup y-axis
                                    $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                    $graph->yaxis->SetLabelMargin(4 * $k);
                                    $graph->yaxis->SetPos('max');
                                    // Intersect at top of x-axis i.e. y axis is at bottom
                                    // First make the labels look right
                                    $graph->yaxis->SetLabelAlign('center', 'top');
                                    if ($percent || $show_percent) {
                                        $graph->yaxis->SetLabelFormat('%d%%');
                                    }
                                    $graph->yaxis->SetLabelSide(SIDE_RIGHT);
                                    $graph->yaxis->scale->SetGrace(10);
                                    // sets 10% headroom
                                    if ($hide_y_axis) {
                                        $graph->yaxis->Hide();
                                    }
                                    if ($hide_grid) {
                                        $graph->ygrid->Show(false);
                                    }
                                    // The fix the tick marks
                                    $graph->yaxis->SetTickSide(SIDE_LEFT);
                                    if ($ylabel) {
                                        $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                        $graph->yaxis->SetTitle($ylabel, 'middle');
                                        $graph->yaxis->SetTitleMargin($yaxislblmargin * $k);
                                        // Finally setup the title
                                        $graph->yaxis->SetTitleSide(SIDE_RIGHT);
                                        // To align the title to the right use :
                                        $graph->yaxis->title->Align('right');
                                        $graph->yaxis->title->SetAngle(0);
                                    }
                                    // Show 0 label on Y-axis (default is not to show)
                                    $graph->yscale->ticks->SupressZeroLabel(false);
                                    // Setup X-axis labels
                                    $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                    $graph->xaxis->title->SetAngle(90);
                                    $graph->xaxis->SetTickLabels($legends);
                                    $graph->xaxis->SetLabelMargin(4 * $k);
                                    // X-axis title
                                    if ($xlabel) {
                                        $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                        $graph->xaxis->SetTitleMargin($xaxislblmargin * $k);
                                        $graph->xaxis->SetTitle($xlabel, 'middle');
                                    }
                                    $group = array();
                                    foreach ($data as $series => $dat) {
                                        $rdata = array();
                                        foreach ($data[$series] as $row) {
                                            $rdata[] = $row;
                                        }
                                        // Create the bar pot
                                        $bplot = new BarPlot($rdata);
                                        $bplot->SetWidth(0.6);
                                        // for SINGLE??
                                        // Setup color for gradient fill style
                                        if ($bandw) {
                                            $bplot->SetPattern($patterns[$series]);
                                        } else {
                                            $bplot->SetFillGradient($fills[$series], "#EEEEEE", GRAD_LEFT_REFLECTION);
                                        }
                                        // Set color for the frame of each bar
                                        $bplot->SetColor("darkgray");
                                        $bplot->SetLegend($labels[$series]);
                                        if ($bandw) {
                                            $bplot->SetShadow("gray5");
                                        }
                                        if ($show_values) {
                                            $bplot->value->Show();
                                            $bplot->value->SetMargin(6 * $k);
                                            $bplot->value->SetColor("darkred");
                                            $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k);
                                            if ($percent || $show_percent) {
                                                $bplot->value->SetFormat('%d%%');
                                            } else {
                                                $bplot->value->SetFormat("%s");
                                            }
                                        }
                                        $group[] = $bplot;
                                    }
                                    if (count($data) == 1) {
                                        $graph->Add($group[0]);
                                    } else {
                                        // Create the grouped bar plot
                                        if ($stacked) {
                                            $gbplot = new AccBarPlot($group);
                                        } else {
                                            $gbplot = new GroupBarPlot($group);
                                        }
                                        $graph->Add($gbplot);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if ($graph) {
            $graph->Stroke(_MPDF_PATH . $figure_file);
            $srcpath = str_replace("\\", "/", dirname(__FILE__)) . "/";
            $srcpath .= $figure_file;
            return array('file' => $srcpath, 'w' => $w, 'h' => $h);
        }
    }
    return false;
}
 function buildGraphic($stats)
 {
     $stat = $stats->getRequests();
     foreach ($stat as $s) {
         $mes = intval($s->getMonth());
         $ano = intval($s->getYear());
         $values[$ano][$mes] = $s->getNumberOfRequests();
     }
     /*
     "gabarito" da linha dos graficos com 12 posicoes, uma para cada mes
     os valores "-" sao considerados NULLs pelo jpgraph
     */
     $data = array("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0");
     /*
     "gabarito" para as cores das linhas do gráfico
     */
     $cores = array("blue", "yellow", "purple", "cyan", "pink", "red", "orange", "green", "black", "sienna", "darkred", "darkgreen");
     // Create the graph. These two calls are always required
     //			$graph = new Graph(700,400,"auto");
     $graph = new Graph(900, 300, "auto");
     $graph->SetScale("textlin");
     /*
     cira um array bi-dimencional contendo array(ano{array com a quantidade de acessos por mes})
     */
     $colorIndex = 0;
     $bars = array();
     foreach ($values as $ano => $meses) {
         /*
         valores será a variavel que servirá de "datasource" para a barra do grafico
         inicialmente ele eh inicializada com o gabarito, e serao preenchidos os valores
         dos meses no laço for logo abaixo
         */
         $valores = $data;
         for ($k = 0; $k <= count($valores); $k++) {
             if ($meses[$k]) {
                 $valores[$k] = $meses[$k];
             }
         }
         if (count($valores) > 12) {
             unset($valores[0]);
         }
         $valores = array_values($valores);
         /*
         aqui eu uso "Variáveis Variáveis" do PHP para poder
         inserir vária linhas no gráfico
         */
         $nome = "barplot" . $ano;
         ${$nome} = new BarPlot($valores);
         $cor = $cores[$colorIndex];
         ${$nome}->SetFillColor($cor);
         ${$nome}->SetColor($cor);
         /*configs para os valores do ponto*/
         ${$nome}->value->SetColor("darkred");
         ${$nome}->value->SetFont(FF_FONT1, FS_BOLD);
         ${$nome}->value->SetFormat("%0.1d");
         //				$$nome->SetWeight(20);
         //				$$nome->SetWidth(20);
         ${$nome}->value->Show();
         ${$nome}->value->iHideZero = true;
         ${$nome}->setLegend($ano);
         /*adicionando a linha ao grafico*/
         $colorIndex++;
         array_push($bars, ${$nome});
     }
     $gbplot = new GroupBarPlot($bars);
     $gbplot->SetWidth(0.9);
     $graph->Add($gbplot);
     $graph->yaxis->scale->SetGrace(20);
     $graph->img->SetMargin(40, 20, 20, 40);
     $graph->title->Set(ARTICLE_ACCESS);
     $graph->xaxis->title->Set(MONTHS);
     $graph->yaxis->title->Set(ACCESSES);
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->SetShadow();
     $graph->xaxis->SetTickLabels(explode(",", MONTH_LIST));
     // Adjust the legend position
     //			$graph->legend->SetLayout(LEGEND_VER);
     $graph->legend->Pos(0.04, 0.092, "", "center");
     $graph->legend->SetLayout(LEGEND_HOR);
     // Display the graph
     $graph->Stroke();
 }
Example #20
0
function drawGraph($tableName)
{
    require_once 'vendor/jpgraph/jpgraph/lib/JpGraph/src/jpgraph.php';
    require_once 'vendor/jpgraph/jpgraph/lib/JpGraph/src/jpgraph_scatter.php';
    require_once 'vendor/jpgraph/jpgraph/lib/JpGraph/src/jpgraph_line.php';
    require_once 'vendor/jpgraph/jpgraph/lib/JpGraph/src/jpgraph_utils.inc.php';
    $GDT = getTableData($tableName);
    $datax = $GDT['kp'];
    $datay = $GDT['kpe'];
    $x1 = array(0, 12);
    $y1 = array(6.58, 22.78);
    // $f = new FuncGenerator('cos($x)+1.5*cos(2*$x)');
    // list($x1,$y1) = $f->E(0,10);
    $graph = new Graph(400, 400);
    $graph->SetScale("linlin");
    $graph->img->SetMargin(60, 30, 30, 30);
    //$graph->img->SetPadding(10,10,10,10)
    $graph->SetShadow();
    $graph->title->Set("Залежність між Кп та Кпе");
    //$graph->title->SetFont(DejaVuSans);
    $graph->yaxis->title->Set('Кп');
    $graph->xaxis->title->Set('Кпе');
    $sp1 = new ScatterPlot($datay, $datax);
    $sp2 = new LinePlot($x1, $y1);
    $graph->Add($sp1);
    $graph->Add($sp2);
    $sp2->SetColor("#f00");
    $sp2->SetWeight(2);
    $graph->Stroke();
}
 /**
  * @depends Jpgraph
  * 
  * Cria jpgraf e grava jpg
  * 
  * retorna URL da imagem jpgraph
  * 
  * @return boolean|string
  * 
  */
 public function gravaImagemGraficaParaPontuacao()
 {
     $dirName = $this->objDevolutive->getDirName();
     $data = $this->getArrPontuacao();
     $total = "100%";
     $points = array();
     foreach ($data as $c) {
         $item = $c['EnterpreneurFeatureId'];
         $points[] = $this->pointsPorcentagem($c['Points'], 'double');
     }
     $titulo_do_grafico = "";
     $titulo_medida_Y = "PORCENTAGEM ( % )";
     $titulo_medida_X = "Caracteristica Empreendedora";
     //$datay=array(12,8,19,3,10,5);
     $datay = array_values($points);
     // Create the graph. These two calls are always required
     $graph = new Graph(600, 500);
     //$graph->SetScale('intlin');
     $graph->SetScale('textlin');
     // Add a drop shadow
     $graph->SetShadow(true, 5);
     // Adjust the margin a bit to make more room for titles
     $graph->SetMargin(50, 50, 40, 50);
     // Create a bar pot
     $bplot = new BarPlot($datay);
     $bplot->SetLegend($titulo_medida_X);
     // Adjust fill color
     $bplot->SetFillColor('orange');
     $graph->Add($bplot);
     // Setup the titles
     $graph->title->Set($titulo_do_grafico);
     $graph->xaxis->title->Set('');
     $graph->yaxis->title->Set($titulo_medida_Y);
     $graph->yscale->SetAutoMax(100);
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD, 11);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $pathImagem = $dirName . self::IMAGE_JPGRAPH_DEVOLUTIVE;
     //echo 'pathImagem: '.$pathImagem; exit;
     // Display the graph
     $graph->Stroke($pathImagem);
     $this->setPathImagem($pathImagem);
     //-------
     //        $criterios = array();
     //        foreach($arrCriteria AS $chave => $valor) {
     //            $criterios[$chave] = utf8_decode(" ".$chave." - ".$valor);
     //        }
     //
     //        if(!is_array($arrRadarData)) {
     //            return false;
     //        }
     //
     //        $titles = array_values($criterios);
     //        $data = array_values($arrRadarData);
     //
     //        $graph = new RadarGraph (635,355);
     //        $graph->SetShadow();
     //        $graph->SetScale('lin', $aYMin=0, $aYMax=100);
     //        $graph->yscale->ticks->Set(50,10);
     //
     //        $graph->title->Set("Porcentagem de acertos por Critério");
     //        $graph->title->SetFont(FF_VERDANA,FS_NORMAL,12);
     //
     //        //$graph->subtitle->Set("Pontuação por Critério em %");
     //        //$graph->subtitle->SetFont(FF_VERDANA,FS_ITALIC,10);
     //
     //        $graph->SetTitles($titles);
     //        $graph->SetCenter(0.50,0.54);
     //        //$graph->HideTickMarks();
     //        $graph->ShowMinorTickMArks();
     //        $graph->SetColor('white');
     //        $graph->grid->SetLineStyle('dashed');
     //        $graph->axis->SetColor('darkgray@0.3');
     //        $graph->grid->SetColor('darkgray@0.3');
     //        $graph->grid->Show();
     //
     //        $graph->SetGridDepth(DEPTH_BACK);
     //
     //        $plot = new RadarPlot($data);
     //        $plot->SetColor('red@0.2');
     //        $plot->SetLineWeight(3);
     //        $plot->SetFillColor('skyblue4@0.7');
     //        $graph->Add($plot);
     //
     //        $radarPath = $dirName."radarTMP.png";
     //
     //        $graph->Stroke($radarPath);
     //
     //        return $radarPath;
 }
Example #22
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_bar.php';
$datay = array(12, 8, 19, 3, 10, 5);
// Create the graph. These two calls are always required
$graph = new Graph(300, 200);
$graph->SetScale('textlin');
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40, 30, 20, 40);
// Create a bar pot
$bplot = new BarPlot($datay);
$graph->Add($bplot);
// Create and add a new text
$txt = new Text("This is a text\nwith many\nand even\nmore\nlines of text");
$txt->SetPos(0.5, 0.5, 'center', 'center');
$txt->SetFont(FF_FONT2, FS_BOLD);
$txt->ParagraphAlign('center');
$txt->SetBox('yellow', 'navy', 'gray');
$txt->SetColor('red');
$graph->AddText($txt);
// Setup the titles
$graph->title->Set("A simple bar graph");
$graph->xaxis->title->Set("X-title");
$graph->yaxis->title->Set("Y-title");
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
Example #23
0
 /**
  * 线图
  */
 function createmonthline($title, $data = array(), $size = 40, $height = 100, $width = 80, $legend = array())
 {
     vendor("Jpgraph.jpgraph");
     vendor("Jpgraph.jpgraph_line");
     $labels = $legend;
     //编码转化
     foreach ($labels as $k => $v) {
         $labels[$k] = iconv('utf-8', 'gb2312', $v);
     }
     $data = $data;
     $graph = new Graph($width, $height, "auto");
     $graph->img->SetMargin(40, 40, 40, 40);
     $graph->img->SetAntiAliasing();
     $graph->SetScale("textlin");
     $graph->SetShadow();
     $graph->title->Set(iconv('utf-8', 'gb2312', "{$title}"));
     $graph->title->SetFont(FF_SIMSUN, FS_NORMAL, 14);
     $graph->SetFrame(false, '#ffffff', 0);
     //去掉周围的边框
     $graph->xaxis->SetFont(FF_SIMSUN, FS_NORMAL, 9);
     $graph->xaxis->SetTickLabels($labels);
     $graph->xaxis->SetLabelAngle(0);
     $p1 = new LinePlot($data);
     $p1->mark->SetType(MARK_FILLEDCIRCLE);
     $p1->mark->SetFillColor("#0080C0");
     $p1->mark->SetWidth(4);
     $p1->SetColor("#000000");
     $p1->SetCenter();
     $graph->Add($p1);
     $graph->Stroke();
 }
Example #24
0
 public static function liner3Show($data_x, $data_y, $x_title, $y_title, $graph_title)
 {
     // echo var_dump($data_x);
     // echo var_dump($data_y);
     $graph = new Graph(LENHSIZE, HEISIZE);
     //创建画布
     $graph->img->SetMargin(LEFT, 80, UP, DOWN);
     //设置统计图所在画布的位置,左边距50、右边距40、上边距30、下边距40,单位为像素
     // $graph->yscale->ticks->Set($max_y/2,1);
     $graph->img->SetAntiAliasing();
     //设置折线的平滑状态
     $graph->SetScale("textlin", 210, 230);
     //设置刻度样式
     $graph->SetShadow();
     //创建画布阴影
     $graph->xgrid->Show();
     $line = new PlotLine(HORIZONTAL, 220, "red", 2);
     //设置红色警戒线
     $line->SetLegend("警戒线");
     $graph->legend->setFont(FF_SIMSUN, FS_BOLD, GRAGHSIZE - 5);
     $graph->AddLine($line, false);
     $graph->title->Set($graph_title);
     //设置标题
     $graph->title->SetFont(FF_SIMSUN, FS_BOLD, GRAGHSIZE);
     //设置标题字体
     $graph->SetMarginColor("lightblue");
     //设置画布的背景颜色为淡蓝色
     $graph->yaxis->title->SetFont(FF_SIMSUN, FS_BOLD);
     //设置Y轴标题的字体
     $graph->xaxis->SetPos("min");
     // $graph->yaxis->HideZeroLabel();
     // $graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
     // $a=array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");   //X轴
     $graph->xaxis->SetTickLabels($data_x);
     //设置X轴
     $graph->xaxis->SetFont(FF_SIMSUN);
     //设置X坐标轴的字体
     // $graph->yscale->SetGrace(20);
     $p1 = new LinePlot($data_y);
     //创建折线图对象
     $p1->mark->SetType(MARK_FILLEDCIRCLE);
     //设置数据坐标点为圆形标记
     $p1->mark->SetFillColor("black");
     //设置填充的颜色
     $p1->mark->SetWidth(3);
     //设置圆形标记的直径为3像素
     $p1->SetColor("blue");
     // $p1->SetYMin(0);
     $graph->Add($p1);
     $graph->InitializeFrameAndMargin();
     $num = rand(0, RAND);
     // echo var_dump($num);
     $name = "Histogrm" . $num . ".png";
     session_start();
     $_SESSION["name"] = $name;
     // echo var_dump($name);
     $graph->Stroke($name);
     return $name;
 }
Example #25
0
 $graph->yaxis->title->Set($noproblems);
 $graph->title->SetFont(FF_FONT1, FS_BOLD);
 $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
 $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
 $graph->xaxis->SetFont(FF_FONT1, FS_BOLD, 8);
 // Setup the values that are displayed on top of each bar
 $bplot->value->Show();
 // Must use TTF fonts if we want text at an arbitrary angle
 $bplot->value->SetFont(FF_FONT1, FS_BOLD);
 $bplot->value->SetAngle(0);
 $bplot->value->SetFormat('%d');
 // Create the graph. These two calls are always required
 $graph2 = new Graph(500, 200, 'auto');
 $graph2->SetScale('textint', 0, max($y2) + max($y2) * 0.2, 0, 0);
 // Add a drop shadow
 $graph2->SetShadow();
 // Adjust the margin a bit to make more room for titles
 $graph2->SetMargin(50, 30, 30, 40);
 // Create a bar pot
 $bplot2 = new BarPlot($y2);
 // Adjust fill color
 $bplot2->SetFillColor('chartreuse3');
 $graph2->Add($bplot2);
 // Setup the titles
 $descibe2 = "Statystyka COG - skrzynki weryfikowane";
 $graph2->title->Set($descibe2);
 $graph2->xaxis->title->Set($xtitle);
 $graph2->xaxis->SetTickLabels($x2);
 $ncaches = tr('number_caches');
 $graph2->yaxis->title->Set($ncaches);
 $graph2->title->SetFont(FF_FONT1, FS_BOLD);
Example #26
0
 public function bytes_s()
 {
     require_once 'jpgraph/jpgraph.php';
     require_once 'jpgraph/jpgraph_line.php';
     require_once 'jpgraph/jpgraph_date.php';
     $size = $this->uri->segment(3);
     $server_id = $this->uri->segment(4);
     $time = $this->uri->segment(5);
     $server = $this->server->get_record_by_id($server_id);
     $start = time() - $time;
     $mcount = $time / 60;
     $data = array();
     $xdata = array();
     for ($i = 0; $i < $mcount; ++$i) {
         $time = $start + $i * 60;
         $xdata[$i] = $time;
         $date_min = date('YmdHi', $time);
         $query = $this->db->query("select Bytes_sent from mysql_status_ext_history where server_id='{$server_id}' and YmdHi = '" . $date_min . "'; ");
         if ($query->num_rows() > 0) {
             $row = $query->row();
             $yresult = $row->Bytes_sent;
         } else {
             $yresult = '0';
         }
         $ydata[$i] = $yresult;
     }
     // Create the graph. These two calls are always required
     if ($size == 'small') {
         $width = 400;
         $height = 260;
     } else {
         if ($size = 'large') {
             $width = 1280;
             $height = 400;
         }
     }
     $graph = new Graph($width, $height);
     //$graph->SetScale("textlin");
     $graph->SetScale('datelin');
     $graph->xaxis->SetLabelAngle(90);
     $graph->xaxis->scale->SetDateFormat('H:i');
     $graph->SetShadow();
     $graph->img->SetMargin(40, 20, 20, 40);
     $dplot = new LinePlot($ydata, $xdata);
     $dplot->SetFillColor("orange@0.3");
     // Add the plot to the graph
     $graph->Add($dplot);
     $graph->xaxis->SetTextTickInterval(2);
     $grapha_title = $server['host'] . ":" . $server['port'] . " " . $server['application'] . " Sent Flow(KB)";
     $graph->title->Set($grapha_title);
     $graph->xaxis->title->Set("");
     $graph->yaxis->title->Set("");
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->Stroke();
 }
Example #27
0
 private function createBarGraph($xdata, $data1, $ytitle)
 {
     // Create the graph.
     $graph = new Graph($this->width, $this->height, "auto");
     $graph->SetScale("textlin");
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->SetFrame(false);
     if ($this->shadow) {
         $graph->SetShadow();
     }
     // Create the bar plot
     $arrPos = array();
     $arrNeg = array();
     foreach ($data1 as &$value) {
         if ($value >= 0) {
             array_push($arrPos, $value);
             array_push($arrNeg, 0);
         } else {
             array_push($arrPos, 0);
             array_push($arrNeg, $value);
         }
     }
     $bplotPos = new BarPlot($arrPos);
     // First group positive
     $bplotPos->SetFillColor('#ababab');
     // color for positive '#ababab' Kulturplanner #8aa571
     $bplotNeg = new BarPlot($arrNeg);
     // second group negative
     $bplotNeg->SetFillColor("#cc00cc");
     //color for negative prologiq "#cc00cc"
     $gbplot = new AccBarPlot(array($bplotPos, $bplotNeg));
     $gbplot->value->Show();
     $gbplot->value->SetFormat('%d');
     $gbplot->value->SetColor("black");
     $gbplot->SetValuePos('center');
     //$gbplot->SetLegend(Prado::localize($this->legend));
     // ... and add it to the graph
     $graph->Add($gbplot);
     $graph->xaxis->title->Set($this->title);
     $graph->xaxis->SetTickLabels($xdata);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->Set($ytitle);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->SetLabelMargin(5);
     $graph->yaxis->scale->SetGrace(10);
     $graph->yaxis->HideZeroLabel();
     $graph->ygrid->SetFill(true, '#f2f2f2@0.6', '#cacaca@0.6');
     return $graph;
 }
Example #28
0
 $graph3->xaxis->SetTickLabels($x3);
 $graph3->yaxis->title->Set($noproblems);
 $graph3->title->SetFont(FF_FONT1, FS_BOLD);
 $graph3->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
 $graph3->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
 // Setup the values that are displayed on top of each bar
 $bplot3->value->Show();
 // Must use TTF fonts if we want text at an arbitrary angle
 $bplot3->value->SetFont(FF_FONT1, FS_BOLD);
 $bplot3->value->SetAngle(0);
 $bplot3->value->SetFormat('%d');
 // Create the graph. These two calls are always required
 $graph4 = new Graph(740, 200, 'auto');
 $graph4->SetScale('textint', 0, max($y4) + max($y4) * 0.2, 0, 0);
 // Add a drop shadow
 $graph4->SetShadow();
 // Adjust the margin a bit to make more room for titles
 $graph4->SetMargin(50, 30, 30, 40);
 // Create a bar pot
 $bplot4 = new BarPlot($y4);
 // Adjust fill color
 $bplot4->SetFillColor('purple1');
 $graph4->Add($bplot4);
 // Setup the titles
 $descibe4 = iconv('UTF-8', 'ASCII//TRANSLIT', tr("octeam_stat_m_caches"));
 $graph4->title->Set($descibe4);
 $graph4->xaxis->title->Set(iconv('UTF-8', 'ASCII//TRANSLIT', tr('number_month')) . '2014/2015');
 $graph4->xaxis->SetTickLabels($x4);
 $graph4->yaxis->title->Set($ncaches);
 $graph4->title->SetFont(FF_FONT1, FS_BOLD);
 $graph4->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
Example #29
0
 public function actionLine($id = -1)
 {
     $data = $this->analyse($id);
     include 'jpgraph/jpgraph.php';
     include 'jpgraph/jpgraph_line.php';
     $ydata = array();
     $xdata = array();
     foreach ($data as $key => $value) {
         array_push($xdata, $key);
         array_push($ydata, $value);
     }
     if (count($data) == 0) {
         echo '近一个习惯起没有相应的反馈级记录';
         die;
     }
     $graph = new Graph(500, 500, 'auto');
     $graph->SetScale('textlin');
     $linePlot = new linePlot($ydata);
     $linePlot->SetColor("blue:0.5");
     $linePlot->value->Show();
     $linePlot->SetWeight(1);
     $graph->Add($linePlot);
     $graph->xaxis->SetTickLabels($xdata);
     // $graph -> xaxis -> SetTextLabelInterval(2);
     $graph->yaxis->SetColor("black");
     $graph->yaxis->SetWeight(2);
     $graph->SetShadow();
     $graph->Stroke();
 }