} } $longest_size++; for ($i = 0; $i < $category_count; $i++) { #echo $data_count_arr[$i]; $percentage = number_format($data_count_arr[$i] / $total * 100, 1); #echo $percentage; $percentage_str = str_pad($percentage, 5, ' ', STR_PAD_LEFT); $data_category_arr[$i] = str_pad($data_category_arr[$i], $longest_size); $data_category_arr[$i] = $data_category_arr[$i] . $percentage_str; if ($percentage < 1) { $data_count_arr[$i] = 0; } } $proj_name = project_get_field($t_project_id, 'name'); # Setup Graph # --- $graph = new PieGraph(800, 600); $graph->SetShadow(); # Set A title for the plot $graph->title->Set("Category Distribution Graph: {$proj_name}"); $graph->title->SetFont(FF_FONT2, FS_BOLD); # Create graph $p1 = new PiePlot($data_count_arr); $p1->SetLegends($data_category_arr); $p1->SetSize(260); $p1->SetCenter(0.35); $p1->SetSliceColors($g_color_arr); $p1->SetStartAngle(-90); $graph->Add($p1); $graph->Stroke();
<?php // Include needed classes require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_pie.php'; // Our data $data = array(78, 22); // Create the Pie Graph $graph = new PieGraph(350, 300, 'auto'); $graph->SetShadow(); // Set A title for the plot + disable the border $graph->title->Set("Percentage of chart which resembles Pac-man"); $graph->SetFrame(false); // Create the pieplot $pieplot = new PiePlot($data); $pieplot->SetCenter(0.5, 0.5); $pieplot->SetStartAngle(39); $pieplot->SetLegends(array('Pac-man', 'Not Pac-Man')); // Add the pieplot to the graph $graph->Add($pieplot); // JpGraph Bug: you must first add the pieplot before you can set the colors (?!) $pieplot->SetSliceColors(array('#FFFF00', '#FF0000')); // Style the Legend $graph->legend->SetFrameWeight(0); $graph->legend->Pos(0.5, 0.9, 'center', 'top'); $graph->legend->SetFillColor('white'); $graph->legend->SetColumns(2); // Display the graph $graph->Stroke();
function baw_render_jpgraph_img() { include_once "../config.php"; if (isset($_GET['type'])) { $type = $_GET['type']; } else { return; } $d = $_GET['d']; $f = $_GET['f']; $count = count($d); $dir = $BAW_CONF['jpgraph_path'] . '/jpgraph.php'; include_once $dir; switch ($type) { case 'bar': include_once $BAW_CONF['jpgraph_path'] . '/jpgraph_bar.php'; break; case 'pie': include_once $BAW_CONF['jpgraph_path'] . "/jpgraph_pie.php"; $size = 0.17; $graph = new PieGraph(600, 250, "auto"); for ($i = 0; $i < 1; $i++) { $p1 = new PiePlot($d[$i]); if ($i == 0) { $p1->SetLegends($d[0]); } $p1->title->Set($f[1]); $p1->SetSize($size); $vert = 0.15 + ($size + 0.1) * $i; $p1->SetCenter($vert, 0.3); $p1->SetStartAngle(0); $p1->SetTheme("sand"); $graph->Add($p1); } $graph->Stroke(); break; case 'line': include_once $BAW_CONF['jpgraph_path'] . "/jpgraph_line.php"; break; } return $out; }
$graph->title->Set($m); $graph->title->SetFont(FF_VERDANA, FS_BOLD, 12); $graph->title->SetColor('black'); $graph->title->SetMargin(10); $graph->subtitle->SetFont(FF_ARIAL, FS_BOLD, 10); $graph->subtitle->Set('Importe Total $ ' . $importe); // Create pie plot $p1 = new PiePlot($datay); $p1->SetSize(0.3); $p1->SetCenter(0.5, 0.32); $p1->ExplodeAll(5); $p1->SetShadow(); $p1->SetSliceColors($color); $p1->SetGuideLines(true, false); $p1->SetGuideLinesAdjust(1.1); $p1->SetStartAngle(200); // Setup the labels to be displayed $p1->SetLabels($name); $p1->SetLegends($datax); $graph->legend->SetPos(0.39, 0.97, 'center', 'bottom'); $graph->legend->SetColumns(2); // This method adjust the position of the labels. This is given as fractions // of the radius of the Pie. A value < 1 will put the center of the label // inside the Pie and a value >= 1 will pout the center of the label outside the // Pie. By default the label is positioned at 0.5, in the middle of each slice. $p1->SetLabelPos(0.55); // Setup the label formats and what value we want to be shown (The absolute) // or the percentage. $p1->SetLabelType(PIE_VALUE_PER); $p1->value->Show(); $p1->value->SetFont(FF_ARIAL, FS_NORMAL, 9);