Пример #1
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_pie.php';
require_once 'jpgraph/jpgraph_pie3d.php';
// Some data
$data = array(array(80, 18, 15, 17), array(35, 28, 6, 34), array(10, 28, 10, 5), array(22, 22, 10, 17));
$piepos = array(0.2, 0.4, 0.65, 0.28, 0.25, 0.75, 0.8, 0.75);
$titles = array('USA', 'Sweden', 'South America', 'Australia');
$n = count($piepos) / 2;
// A new graph
$graph = new PieGraph(550, 400, 'auto');
// Specify margins since we put the image in the plot area
$graph->SetMargin(1, 1, 40, 1);
$graph->SetMarginColor('navy');
$graph->SetShadow(false);
// Setup background
$graph->SetBackgroundImage('worldmap1.jpg', BGIMG_FILLPLOT);
// Setup title
$graph->title->Set("Pie plots with background image");
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 20);
$graph->title->SetColor('white');
$p = array();
// Create the plots
for ($i = 0; $i < $n; ++$i) {
    $d = "data{$i}";
    $p[] = new PiePlot3D($data[$i]);
}
// Position the four pies
for ($i = 0; $i < $n; ++$i) {
     $XchartData[] = strlen($myKey) > 0 ? $myKey : "Unknown";
     if (isset($fields[$content['chart_field']]['SearchField']) && strlen($myKey) > 0) {
         $chartImageMapLinks[] = $content['BASEPATH'] . "index.php?filter=" . $fields[$content['chart_field']]['SearchField'] . "%3A%3D" . urlencode($szEncodedKeyStr) . "&search=Search";
     } else {
         $chartImageMapLinks[] = "";
     }
     $chartImageMapAlts[] = $fields[$content['chart_field']]['FieldCaption'] . ": " . $myKey;
     $chartImageMapTargets[] = "_top";
 }
 if ($content['chart_type'] == CHART_CAKE) {
     // Include additional code filers for this chart!
     include_once $gl_root_path . "classes/jpgraph/jpgraph_pie.php";
     include_once $gl_root_path . "classes/jpgraph/jpgraph_pie3d.php";
     // Create Basic Image, and set basic properties!
     $graph = new PieGraph($content['chart_width'], $content['chart_width'], 'auto');
     $graph->SetMargin(30, 20, 30, 30);
     // Adjust margin area
     $graph->SetScale("textlin");
     $graph->SetMarginColor('white');
     $graph->SetBox();
     // Box around plotarea
     // Set up the title for the graph
     //					$graph->title->Set('Messagecount sorted by "' . $content[ $fields[$content['chart_field']]['FieldCaption'] ] . '"');
     //					$graph->title->SetFont(FF_VERDANA,FS_NORMAL,12);
     //					$graph->title->SetColor("darkred");
     // Setup the tab title
     $graph->tabtitle->Set(GetAndReplaceLangStr($content['LN_STATS_CHARTTITLE'], $content['maxrecords'], $fields[$content['chart_field']]['FieldCaption']));
     $graph->tabtitle->SetFont(FF_VERA, FS_BOLD, 9);
     $graph->tabtitle->SetPos('left');
     // Set Graph footer
     $graph->footer->left->Set("LogAnalyzer v" . $content['BUILDNUMBER'] . "\n" . GetAndReplaceLangStr($content['LN_STATS_GENERATEDAT'], date("Y-m-d")));
Пример #3
0
    $legends[] = $currentLabel . ' - ' . $amounts[$currentKey]->getFormatted();
}
$targets = array();
foreach ($labels as $currentId => $currentLabel) {
    if ($currentId != 'none' && $currentId != 'other') {
        $targets[] = 'javascript:reachThroughCategory(\'' . substr($currentId, 1) . '\');';
    } else {
        $targets[] = '';
    }
}
$pie = new PiePlot3D($data);
$pie->SetLegends($legends);
$pie->SetCSIMTargets($targets, $dataNames);
$pie->value->SetFont(FF_VERA);
$pie->value->SetFormatCallback('formatPercentage');
$pie->SetCenter(0.33, 0.5);
//$pie->SetSliceColors($chartColors);
$graph->Add($pie);
$graph->legend->SetFont(FF_VERA);
$graph->legend->SetPos(0.03, 0.05);
$graph->SetMargin(10, 10, 10, 10);
$graph->SetShadow();
$graph->SetAntiAliasing();
$graph->StrokeCSIM(basename(__FILE__));
require_once BADGER_ROOT . "/includes/fileFooter.php";
function formatPercentage($val)
{
    global $us;
    $str = sprintf('%1.2f %%', $val);
    return str_replace('.', $us->getProperty('badgerDecimalSeparator'), $str);
}
Пример #4
0
 public function create_graph($width = 600, $height = 200, $data, $title, $xaxis, $yaxis, $type = "bar")
 {
     require_once 'jpgraph/jpgraph.php';
     require_once 'jpgraph/jpgraph_line.php';
     require_once 'jpgraph/jpgraph_bar.php';
     require_once 'jpgraph/jpgraph_pie.php';
     // Create a graph instance
     if ($type == "bar" || $type == "line") {
         $graph = new Graph($width, $height);
     } else {
         if ($type == "pie") {
             $graph = new PieGraph($width, $height);
         }
     }
     // Specify what scale we want to use,
     // int = integer scale for the X-axis
     // int = integer scale for the Y-axis
     $graph->SetScale('intint');
     $graph->SetMarginColor("lightblue:1.1");
     $graph->SetShadow();
     $graph->SetMargin(60, 20, 10, 40);
     // Box around plotarea
     $graph->SetBox();
     // No frame around the image
     $graph->SetFrame(false);
     // Setup a title for the graph
     $graph->title->Set($title);
     $graph->title->SetMargin(8);
     $graph->title->SetColor("darkred");
     // Setup the X and Y grid
     $graph->ygrid->SetFill(true, '#DDDDDD@0.5', '#BBBBBB@0.5');
     $graph->ygrid->SetLineStyle('dashed');
     $graph->ygrid->SetColor('gray');
     $graph->xgrid->Show();
     $graph->xgrid->SetLineStyle('dashed');
     $graph->xgrid->SetColor('gray');
     // Setup titles and X-axis labels, if it's array, first row is title
     if (is_array($xaxis)) {
         $graph->xaxis->title->Set($xaxis[0]);
         $xaxis = array_slice($xaxis, 1, count($xaxis) - 1);
         $graph->xaxis->SetTickLabels($xaxis);
     } else {
         $graph->xaxis->title->Set($xaxis);
     }
     // no array, just show name
     // Setup Y-axis title
     $graph->yaxis->title->SetMargin(10);
     $graph->yaxis->title->Set($yaxis);
     if ($type == "bar") {
         $plot = new BarPlot($data);
         $plot->SetWidth(0.6);
         $fcol = '#440000';
         $tcol = '#FF9090';
         $plot->SetFillGradient("navy:0.9", "navy:1.85", GRAD_LEFT_REFLECTION);
         //$plot->SetColor("black");
         // Set line weigth to 0 so that there are no border
         // around each bar
         $plot->SetWeight(0);
         // Add the plot to the graph
         $graph->Add($plot);
     } else {
         if ($type == "line") {
             $plot = new LinePlot($data);
             $plot->SetFillColor('skyblue@0.5');
             $plot->SetColor('navy@0.7');
             $plot->mark->SetType(MARK_SQUARE);
             $plot->mark->SetColor('blue@0.5');
             $plot->mark->SetFillColor('lightblue');
             $plot->mark->SetSize(5);
             // Add the plot to the graph
             $graph->Add($plot);
         } else {
             if ($type == "pie") {
                 $plot = new PiePlot($data);
                 $plot->SetCenter(0.5, 0.55);
                 $plot->SetSize(0.2);
                 // Enable and set policy for guide-lines
                 $plot->SetGuideLines();
                 $plot->SetGuideLinesAdjust(1.4);
                 // Setup the labels
                 $plot->SetLabelType(PIE_VALUE_PER);
                 $plot->value->Show();
                 //$plot->value->SetFont(FF_ARIAL,FS_NORMAL,9);
                 $plot->value->SetFormat('%2.1f%%');
                 $plot->ExplodeSlice(1);
                 $plot->SetGuideLines(true);
                 $graph->SetMarginColor("white");
                 $plot->SetLegends($xaxis);
                 // Add the plot to the graph
                 $graph->Add($plot);
             } else {
                 die($type . " is not known graph type");
             }
         }
     }
     // Display the graph
     $fn = strtolower($title);
     $fn = str_replace(" ", "", $fn);
     $filename_relative = "site/web_app/images/dynamic/{$fn}.jpg";
     $filename_full = __DIR__ . "/" . $filename_relative;
     $graph->Stroke($filename_full);
     $imglink = "<img src='{$filename_relative}' title='{$title}' />\n";
     return $imglink;
 }
Пример #5
0
     break;
 case 'wins_in_game':
     if (!isset($_GET['map_id'])) {
         die('No map id given');
     }
     require_once 'core/jpgraph/jpgraph_pie.php';
     // Get data
     $wins = $db->GetRow("SELECT mapstat_alien_wins,\n                                mapstat_human_wins,\n                                mapstat_ties + mapstat_draws AS ties\n                         FROM map_stats WHERE mapstat_id = ?", array($_GET['map_id']));
     if ($wins['mapstat_alien_wins'] + $wins['mapstat_human_wins'] + $wins['ties'] > 0) {
         $data = array($wins['mapstat_alien_wins'], $wins['mapstat_human_wins'], $wins['ties']);
     } else {
         $data = array(0, 0, 1);
     }
     // Build graph
     $g = new PieGraph(200, 120);
     $g->SetMargin(30, 30, 10, 25);
     $g->SetMarginColor('#22262a');
     $g->SetColor('#22262a');
     $g->SetFrame(true, array(0, 0, 0), 0);
     $g->SetBox(false);
     // Build plot
     $p1 = new PiePlot($data);
     $p1->SetCenter(40, 60);
     $p1->SetSliceColors(array('#CC0000', '#0055FF', '#888888'));
     $p1->value->show(false);
     $legends = array('Aliens (%d%%)', 'Humans (%d%%)', 'Tied (%d%%)');
     $p1->SetLegends($legends);
     $g->legend->SetShadow(false);
     $g->legend->SetAbsPos(10, 60, 'right', 'center');
     // Stroke
     $g->Add($p1);