Ver Mensaje Individual
  #7 (permalink)  
Antiguo 16/02/2011, 16:27
Avatar de HiToGoRoShi
HiToGoRoShi
 
Fecha de Ingreso: abril-2008
Mensajes: 849
Antigüedad: 16 años
Puntos: 31
Respuesta: ayuda con CACHE (jpgraph)

Esta es la vista que recibe los datos del grafico
Código PHP:
Ver original
  1. <?php
  2. //$data = array(50, 85, 54, 94);
  3. //Detalles
  4. //$label = array('Horizonte RN', 'Integra RN', 'Prima RN', 'Profuturo RN');
  5. $color['color']  = $color;
  6. $color['sombra'] = $sombra;
  7. $path = barchart($data, $label, $color, $p);
  8. //Imprimiendo la fucking IMAGEN
  9. echo img($path);
  10. ?>

ESte es la funcion que para que cree la imagen es un plugin que hice para CI

Cita:
$data son los valores
$label son los nombres
$color el color
$p el turno de la imagen, es un valor de 0 al X ya que la imagen puede ser mostrada X veces pero con diferentes valores, y para evitar que imprima la misma imagen le agrego un prefijo para que asi traiga la imagen correcta en el foreach
Código PHP:
Ver original
  1. function barchart ($data, $label, $color, $p)
  2. {
  3.     require_once ("jpgraph/jpgraph.php");
  4.     require_once ("jpgraph/jpgraph_bar.php");
  5.     // Create the graph. These two calls are always required
  6.     $graph = new Graph(480, 240);
  7.     //Detalle
  8.     $graph->SetScale("textlin");
  9.     $graph->xaxis->SetTickLabels($label);
  10.     //Margin
  11.     $graph->SetMarginColor('white');
  12.     $graph->SetFrame(false);
  13.    
  14.     $bplot = new BarPlot($data);
  15.     //Ancho
  16.     $bplot->SetWidth(0.6);    
  17.     $bplot->SetWeight(0);
  18.     //Colores
  19.     $bplot->SetFillColor($color['color']);
  20.     //Sombras
  21.     $bplot->SetShadow($color['sombra'],12,15,true);
  22.     //Mostrar valores
  23.     $bplot->value->Show();
  24.     $bplot->SetValuePos("center");
  25.    
  26.     $graph->Add($bplot);
  27.    
  28.     $a = rand(0,100);
  29.    
  30.     // Could possibly add to config file if necessary
  31.     $graph_temp_directory = 'temp/rentabilidad/'; // in the webroot (add directory to .htaccess exclude)
  32.     $graph_file_name = 'rentabilidad_neta_'.$p.'.png';
  33.     $graph_file_location = $graph_temp_directory . '/' . $graph_file_name;
  34.     $graph->Stroke('./' . $graph_file_location);
  35.    
  36.     return base_url().$graph_file_location;
  37. }