public function getGrafmayorcosto()
{
JpGraph::module('bar');
$graph = new Graph(680, 300);
$graph->SetScale("textlin");
$graph->yscale->SetGrace(5);
$graph->SetBox(true);
$labels = array();
$valores = array();
foreach (Activo::where('id', '>', '0')->orderBy('costo', 'desc')->take(10)->get() as $activo) {
$labels[] = $activo->num_activo;
$valores[] = $activo->costo;
}
//titulo de la grafica
$graph->title->SetColor('black');
$graph->title->Set('Gráfica: Activos con Mayor Costo');
//valores de los labels en ambas axis y como se ubicaran
$graph->xaxis->SetTickLabels($labels);
$graph->xaxis->SetLabelAlign('center', 'top', 'center');
$graph->ygrid->SetFill(false);
$graph->yaxis->HideLabels(false);
$graph->yaxis->HideTicks(false, false);
//Fonts para las axis
$graph->xaxis->SetColor('black');
$graph->yaxis->SetColor('black');
//grafica de activos con mayor costo
$mayorCosto = new BarPlot($valores);
$mayorCosto->SetColor('white');
$mayorCosto->SetWidth(0.6);
//agrega la grafica generada a la instancia de la grafica
$graph->Add($mayorCosto);
//Despliega la grafica
$graph->Stroke();
}
/**
* Show Horizontal Bar graph
*/
function ShowHBar(&$legend, &$value)
{
$height = 50 + count($value) * 18;
$width = 500;
// Set the basic parameters of the graph
$graph = new Graph($width, $height, 'auto');
$graph->SetScale("textlin");
$top = 30;
$bottom = 20;
$left = 100;
$right = 50;
$graph->Set90AndMargin($left, $right, $top, $bottom);
$graph->xaxis->SetTickLabels($legend);
$graph->SetFrame(false);
// 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($value);
$bplot->SetFillColor("orange");
$bplot->SetWidth(0.5);
// We want to display the value of each bar at the top
$graph->yaxis->scale->SetGrace(10);
$graph->yaxis->SetLabelAlign('center', 'bottom');
$graph->yaxis->SetLabelFormat('%d');
$bplot->value->Show();
$bplot->value->SetFormat('%.d votes');
// Setup color for gradient fill style
$bplot->SetFillGradient("navy", "lightsteelblue", GRAD_MIDVER);
$graph->Add($bplot);
$graph->Stroke();
}
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;
}
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;
}
function conf__grafico(toba_ei_grafico $grafico)
{
if (isset($this->datos)) {
$datos = array();
$leyendas = array();
foreach ($this->datos as $value) {
$datos[] = $value['resultado'];
$leyendas[] = $value['codc_uacad'];
}
}
require_once toba_dir() . '/php/3ros/jpgraph/jpgraph.php';
require_once toba_dir() . '/php/3ros/jpgraph/jpgraph_bar.php';
// Setup a basic graph context with some generous margins to be able
// to fit the legend
$canvas = new Graph(900, 300);
$canvas->SetMargin(100, 140, 60, 40);
$canvas->title->Set('Cr�dito Disponible');
//$canvas->title->SetFont(FF_ARIAL,FS_BOLD,14);
// For contour plots it is custom to use a box style ofr the axis
$canvas->legend->SetPos(0.05, 0.5, 'right', 'center');
$canvas->SetScale('intint');
//$canvas->SetAxisStyle(AXSTYLE_BOXOUT);
//$canvas->xgrid->Show();
$canvas->ygrid->Show();
$canvas->xaxis->SetTickLabels($leyendas);
// A simple contour plot with default arguments (e.g. 10 isobar lines)
$cp = new BarPlot($datos);
$cp->SetColor("#B0C4DE");
$cp->SetFillColor("#B0C4DE");
$cp->SetLegend("Resultado");
$canvas->Add($cp);
// Con esta llamada informamos al gr�fico cu�l es el gr�fico que se tiene
// que dibujar
$grafico->conf()->canvas__set($canvas);
}
/**
*Funcion que crea graficas tipo Barra
*@param array() $data Array en el cual estan los datos para Y array(1, 2.3, 3, 4)
*@param string $legend Título de los datos de la Barra
*@param string $color Color de la Barra
*/
function Bar($data, $legend = null, $color = '#000000')
{
vendor('jpgraph/jpgraph_bar');
$bar = new BarPlot($data);
$bar->SetFillColor($color);
$bar->Legend($legend);
$this->graph->Add($bar);
}
开发者ID:boriscy,项目名称:upsys,代码行数:14,代码来源:jpgraph.php
示例10: execute
function execute()
{
$this->set_title('Statistics Center');
$this->tree('Statistics Center');
if (!extension_loaded('gd')) {
return $this->message('JpGraph Error', 'You need to install the correct GD libraries to run the Statistics centre (GD Libraries were not detected)');
}
include '../lib/jpgraph/jpgraph.php';
include '../lib/jpgraph/jpgraph_bar.php';
if (!defined('IMG_PNG')) {
return $this->message('JpGraph Error', 'This PHP installation is not configured with PNG support. Please recompile PHP with GD and JPEG support to run JpGraph. (Constant IMG_PNG does not exist)');
}
/**
* Posts
*/
$query = $this->db->query("\r\n\t\tSELECT\r\n\t\t COUNT(post_id) AS posts,\r\n\t\t FROM_UNIXTIME(post_time, '%b %y') AS month\r\n\t\tFROM {$this->pre}posts\r\n\t\tGROUP BY month\r\n\t\tORDER BY post_time");
$data = array();
while ($item = $this->db->nqfetch($query)) {
$data[$item['month']] = $item['posts'];
}
if (!$data) {
$data = array(0, 0);
}
$graph = new Graph(400, 300, 'auto');
$graph->SetScale('textint');
$graph->SetColor('aliceblue');
$graph->SetMarginColor('white');
$graph->xaxis->SetTickLabels(array_keys($data));
$graph->yaxis->scale->SetGrace(20);
$graph->title->Set('Posts by Month');
$temp = array_values($data);
$barplot = new BarPlot($temp);
$barplot->SetFillColor('darkorange');
$graph->add($barplot);
$graph->Stroke("{$this->time}1.png");
/**
* Registrations
*/
$query = $this->db->query("\r\n\t\tSELECT\r\n\t\t COUNT(user_id) AS users,\r\n\t\t FROM_UNIXTIME(user_joined, '%b %y') AS month\r\n\t\tFROM {$this->pre}users\r\n\t\tWHERE user_joined != 0\r\n\t\tGROUP BY month\r\n\t\tORDER BY user_joined");
$data = array();
while ($item = $this->db->nqfetch($query)) {
$data[$item['month']] = $item['users'];
}
$graph = new Graph(400, 300, 'auto');
$graph->SetScale('textint');
$graph->SetColor('aliceblue');
$graph->SetMarginColor('white');
$graph->xaxis->SetTickLabels(array_keys($data));
$graph->yaxis->scale->SetGrace(20);
$graph->title->Set('Registrations by Month');
$temp = array_values($data);
$barplot = new BarPlot($temp);
$barplot->SetFillColor('darkorange');
$graph->add($barplot);
$graph->Stroke("{$this->time}2.png");
return $this->message('Statistics Center', "<img src='{$this->time}1.png' alt='Posts by Month' /><br /><br />\r\n\t\t<img src='{$this->time}2.png' alt='Registrations by Month' />");
}
请发表评论