Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/08/2011, 10:47
mixzplit
 
Fecha de Ingreso: enero-2011
Ubicación: Maracaibo
Mensajes: 179
Antigüedad: 13 años, 4 meses
Puntos: 2
AJAX y JPGRAPH

Buenos dias Compañeros foreros, tengo una falla en el resultado de mi codigo, en uno tengo un codigo JavaScript AJAX donde tambien tengo un select con 3 estatus, al seleccionar uno de estos, me ejecuta el codigo AJAX y me deberia generar una grafica en JpGraph, me muestra una cantidad enorme de codigos extraños y no doy con la solucion, no se si la libreria jpGraph no funciona con AJAX, aqui les dejo mi codigo

graficos_semanas.php

Código PHP:
<?php
session_start
();
if(!isset(
$_SESSION['us_id'])){
header("Location: ../index.php"); 
} else {
$usuario=$_SESSION['us_id'];
$admin=$_SESSION['us_tipo'];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<script type="text/javascript" src="./Scripts/imprimir.js"></script>
<script type="text/javascript" src="./Scripts/jquery-1.6.1.js"></script>
<script type="text/javascript" src="accion.js"></script>
<script type="text/javascript" src="./Scripts/jquery.jqtransform.js"></script>
<link rel=stylesheet href="./Style/default.css" type="text/css">
<link rel=stylesheet href="./Style/menuH.css" type="text/css">
<link rel=stylesheet href="./Style/jqtransform.css" type="text/css">
</head>
<script type="text/javascript">
$(function() {
    //Todos los formularios con clase jqtransform
     $('form').jqTransform({imgPath:'.Style/img/'});
 
});
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","graficos/graph_tarea_semana.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
    
include('menu.php');
?>
<form>
<div class="centrado">
<table id="tablas">
<tr>
    <th>Buscar por Estatus:</th>
    <td><select name="users" onchange="showUser(this.value)">
        <option value="">---Seleccione---</option>
        <option value="Pendiente">Pendiente</option>
        <option value="En Proceso">En Proceso</option>
        <option value="Terminado">Terminado</option>
        <!-- <option value="todo">Todos</option> -->
    </select>
    </td>
</tr>
</table>
</div>
<br />

</form>
<div id="txtHint" class="centrado"><b>Mostrando</b></div>
</body>
</html>
<? ?>
y en este genero la grafica

graph_tarea_semana.php

Código PHP:
<?php
   
    
include("../conexion.php");
    include(
'../Scripts/funcion.php');
    include(
"../Scripts/jpgraph/src/jpgraph.php");
    include(
"../Scripts/jpgraph/src/jpgraph_bar.php");
    
    
$status_sel=$_GET["q"];

   echo 
$status_sel;
    
    
$conexion = new ControlBD();
    
$conexion->conectar();
    
$conexion->seleccionarBD();
    
$ano date("Y");
    
set_time_limit(0);
    if (
$status_sel == 'Terminado'){
    
$query "SELECT COUNT(ta_status),WEEK(ta_fechaentrega)as Semana,ta_idrecurso,
               DATE_SUB(ta_fechaentrega,INTERVAL WEEKDAY(ta_fechaentrega) DAY) as primerDiaSemana,
               DATE_ADD(DATE_SUB(ta_fechaentrega,INTERVAL WEEKDAY(ta_fechaentrega) DAY),INTERVAL 6 DAY) as ultimoDiaSemana
                FROM cgtarea WHERE ta_status = '$status_sel'
                GROUP BY Semana"
;
    
$result=$conexion->ejecutarQuery($query);
    
    }else{
    
$query "SELECT COUNT(ta_status),WEEK(req_date)as Semana,ta_idrecurso,DATE_SUB(req_date,INTERVAL WEEKDAY(req_date) DAY) as primerDiaSemana,
               DATE_ADD(DATE_SUB(req_date,INTERVAL WEEKDAY(req_date) DAY),INTERVAL 6 DAY) as ultimoDiaSemana
                FROM cgtarea INNER JOIN cgrequerimientos ON req_id = ta_idreq
                    WHERE ta_status = '$status_sel'
                GROUP BY Semana"
;
    
$result=$conexion->ejecutarQuery($query);
    }
    
    while(
$row mysql_fetch_array($result))
    {
     
$status[] = $row[0];
     
$semanas[] = $row[1];
     
$rango[] = cambiar_fecha($row[3])." al ".cambiar_fecha($row[4]);
    }
    
    
$graph = new Graph(690550"auto");  
    
$graph->ClearTheme();
    
$graph->SetScale"textlin");
    
    
/*Aqui coloco el grafico de forma horizontal*/
    //$graph->Set90AndMargin(40,40,40,40); //LEFT,RIGT,TOP,BOTTOM
    // $graph->img->SetAngle(90); 
    
    
$graph->img->SetMargin(654055190); //(90, 65, 60, 80); Medidas Grafico Horizontal //LEFT,RIGT,TOP,BOTTOM
    
$graph->SetShadow();
    
$graph->xaxis->SetTickLabels($rango);
    
$graph->xaxis->SetLabelAngle(90);
    
$graph->yaxis->HideZeroLabel(); //elimina el 0 del eje de la Y
    
    
$graph->legend->Pos(0.05,0.15,"right","center");
    
$graph->legend->SetShadow('[email protected]');
    
$graph->legend->SetFillColor('[email protected]');

    
$graph->title->Set("Grafico de Tareas");
    
$graph->subtitle->Set("Tareas Terminadas por Semanas");
    
$graph->subtitle->SetFont(FF_VERDANAFS_NORMAL10);
    
$graph->SetTitleBackground('#[email protected]',TITLEBKG_STYLE2,TITLEBKG_FRAME_FULL,'#[email protected]',5,25,true);
    
$graph->yaxis->title->Set("# de tareas x semana" );
    
$graph->xaxis->title->Set("# de Semana de $ano" );
    
$graph->yaxis->SetTitleMargin(30); //LEFT,RIGT,TOP,BOTTOM
    //$graph->yaxis->title->SetAngle(90); //le doy angulo a los Labels del eje de las Y
    
$graph->yaxis->SetTitleMargin(50);
    
$graph->xaxis->SetTitleMargin(150);
    
$graph->ygrid->SetColor('lightgray'); //Color a las lineas del grid
    
$graph->ygrid->SetFill(true,'lightgray','white');  //color entre las lineas de grid  
    
$graph->yaxis->scale->SetGrace(20); //Setea la escala en el eje de las Y
    
    
$barplot = new BarPlot($status);
    
$barplot->SetColor("orange");
    
$barplot->SetFillColor("orange");
    
$barplot->SetShadow('[email protected]');
    
$barplot->SetWidth(0.3);
    
$barplot->value->Show(1);
    
//$barplot->value->SetFormat("%0.1f KG");
    
$barplot->value->SetFont(FF_FONT1,FS_BOLD);

    
$graph->Add($barplot);
    
// Mostramos la imagen
    
$graph->Stroke();

  
?>
El codigo AJAX si me funciona por que cada vez que selecciono un Estatus hace el cambio y me muestrar codigos distintos, ademas le pase un ECHO a la variable a ver si estaba recibiendo bien los datos, pero me muestra puros simbolos y no el grafico.

Espero puedan ayudarme con esto, SALUDOS