Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/01/2015, 15:09
tapazava
 
Fecha de Ingreso: noviembre-2012
Mensajes: 1
Antigüedad: 11 años, 5 meses
Puntos: 0
Respuesta: JpGraph modificar color de las barras de la grafica

<?php
date_default_timezone_set('America/Bogota');
require_once ('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_bar.php');

$graph = new Graph(450,350);

$graph->SetScale('textlin',0,100);
$graph->yaxis->scale->ticks->Set(10);// Establecer los intervalos de y

//Ajuste el margen un poco para hacer más espacio para los títulos
$graph->img->SetMargin(40,30,20,40); //(IZQ,DER,ARR,ABJ)

//Configurar el fondo de la grafica defecto Rayas y cebras
$graph->ygrid->Show(true);
$graph->ygrid->SetFill(false);
// Para el fondo para ser degradado, se necesita setfill primero.
//$graph->SetBackgroundGradient('#990000', '#FFFFFF', GRAD_HOR, BGRAD_PLOT);
//$graph->SetBackgroundGradient('white','lightblue',GRAD_HO R,BGRAD_PLOT);

$graph->xaxis->SetTickLabels(array('P1','P2','P3','P4','P5','P6' ,'P7'));
$datay=array(10,50,20,75,10,15,95); // el valor de cada barrra

// Create a bar pot
$bplot = new BarPlot($datay);
$graph->Add($bplot);
//muestra los valores en la grafica
$bplot->value->Show();
$bplot->value->SetFormat("%01d%%");
$bplot->value->SetColor("#575757");
$color='';
// configuracion de las barras
for($i=0;$i<count($datay);$i++)
{
if($datay[$i]>=0 and $datay[$i]<=30)
{
$datay_color[$i]=array("#d9534f","white",GRAD_LEFT_REFLECTION);
}
else if($datay[$i]>30 and $datay[$i]<=60)
{
$datay_color[$i]=array("#ec971f","white",GRAD_LEFT_REFLECTION);
}
else if($datay[$i]>60 and $datay[$i]<=85)
{
$datay_color[$i]=array("#286090","white",GRAD_LEFT_REFLECTION);
}
else if($datay[$i]>85 and $datay[$i]<=100)
{
$datay_color[$i]=array("#449d44","white",GRAD_LEFT_REFLECTION);

}

}

$bplot->SetFillGradient($datay_color);

$bplot->SetColor("white");
//$bplot->SetFillGradient("#989898","white",GRAD_LEFT_REFLE CTION);
$bplot->SetWidth(30);
$graph->title->Set("Bar Gradient(Left reflection)");

// Setup the titles
$graph->title->SetColor('#000000');
$graph->title->Set("Gráfica de avances");
$graph->xaxis->title->SetColor('#000000');
$graph->xaxis->title->Set("# Participantes");
$graph->yaxis->title->SetColor('#000000');
$graph->yaxis->title->Set("Porcentaje");

// la linea siguiente muestro en mi HTML la grafica como una imagen normal
$graph->Stroke();

?>