Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/07/2010, 23:33
Avatar de sychowaves
sychowaves
 
Fecha de Ingreso: junio-2010
Ubicación: Caracas - Venezuela
Mensajes: 21
Antigüedad: 13 años, 10 meses
Puntos: 0
Pregunta Graficos de Barra Que le falta al codigo

Me an pasado Este scrip bastante completo pero al final no comprendo que variables debo colocar en el HTML para que el grafico aparenca aqui les dejo el codigo

Estilos utilizados


Código CSS:
Ver original
  1. .fondodiv {
  2.     position: relative;
  3.     border-style: ridge;
  4.     border-width: 1px;
  5.     font-size: 10px;
  6.     font-weight: bold;
  7.     vertical-align: bottom;
  8.     text-align: center;
  9. }
  10. .lila {
  11.     position: absolute;
  12.     background-color: #CC99FF;
  13.     border-color: #CC99FF;
  14.     color: white;
  15.     width: 75px;
  16.     vertical-align: middle;
  17. }
  18. .azul {
  19.     position: absolute;
  20.     color: white;
  21.     background-color: #4444FF;
  22.     border-color: #4444FF;
  23.     width: 75px;
  24.     vertical-align: middle;
  25. }
  26. .pequeno {
  27.   font-size: 8px;
  28.     font-style: italic;
  29. }

Código JavaScript

Código Javascript:
Ver original
  1. var ancho=48;
  2. var ano=new Array("1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005");
  3. var Datos=new Array(1131, 1763, 2927, 4917, 5992, 7055, 8825, 9614, 8077, 7780, 7947, 4128);
  4. var Fecha=new Date(2005,10,20);     // LOS MESES EMPIEZAN DESDE 0 =< HAY QUE PONER EL MES ACTUAL MENOS 1
  5. var F_Escala=25;
  6.  
  7. function Rellena_Ceros(cadena,N)  // Funcion que antepone ceros a una cadena hasta alcazar
  8. {                                 // una longitud N. Si N es menor que la longitud, no pone ninguno.
  9. var k=0;
  10. var resultado=cadena.toString();
  11. for (k=resultado.length; k<N; k++)
  12.         resultado="0" + resultado.toString();
  13. return resultado;
  14. }
  15.  
  16. function Puntua(valor)        //Funcion que pone el punto separador de los millares, etc.
  17. {
  18. var i=0;
  19. var resultado=Rellena_Ceros((valor&#37;1000),3);
  20. var resultado=valor%1000;
  21. var tmp=parseInt(valor/1000);
  22. while (tmp>0)
  23.     {
  24.     resultado=Rellena_Ceros((tmp%1000),3) + "." + resultado;
  25.     tmp=parseInt(tmp/1000);
  26.     }
  27. while (resultado.charAt(0)=="0")            // Quitar los 0 iniciales
  28.     resultado=resultado.substring(1,resultado.length);
  29. return resultado;
  30. }
  31.  
  32. function Representa()          // Funcion que representa el grafico excepto la prevision
  33. {
  34. var i=0;
  35. var contenido;
  36. window.document.getElementById("fondo").style.width=ano.length*(ancho+5)+20;
  37. window.document.getElementById("fondo").style.background= "#FFFFCC";
  38. window.document.getElementById("fecha").innerHTML="Datos en miles a fecha: " + Fecha.getDate() + "/" +
  39.             (Fecha.getMonth()+1) + "/" + Fecha.getFullYear();
  40. for (i=0; i<ano.length; i++)
  41.     {
  42.     posicion=(i*(ancho+5))+10;
  43.     altura=Datos[i]/F_Escala;
  44.     valor=Puntua(Datos[i]);
  45.     contenido=window.document.getElementById("fondo").innerHTML;
  46.     window.document.getElementById("fondo").innerHTML=contenido + "<div class=\'azul\' id=\'" + ano[i].toString() +
  47.             "\' style=\'z-index: 1; bottom: 30px;\' title=\'" + valor + "\'>" + Datos[i] + "</div>";
  48.     window.document.getElementById(ano[i]).style.bottom=30;
  49.     window.document.getElementById(ano[i]).style.left=posicion;
  50.     window.document.getElementById(ano[i]).style.height=altura;
  51.     window.document.getElementById(ano[i]).style.width=ancho;
  52.     contenido=window.document.getElementById("fondo").innerHTML;
  53.     window.document.getElementById("fondo").innerHTML=contenido + "<span style=\'color: #000077; position: absolute; bottom: 15px; left: " +
  54.          (posicion+10) + "px;\'>" + ano[i] + "</span>"
  55.         }
  56. Prevision(i-1);      // Representar la prevision en función de los datos del ultimo año
  57. }
  58.  
  59. function Prevision(V)
  60. {
  61. var contenido;
  62. Origen = new Date(Fecha.getFullYear(),0,1);         // Primer dia del año
  63. Final = new Date(Fecha.getFullYear(),11,31);            // Ultimo dia del año
  64. N_Dias=1+(Final.valueOf()-Origen.valueOf())/86400000;       // Dias totales del año, por si es bisiesto
  65. Dias=1+(Fecha.valueOf()-Origen.valueOf())/86400000;     // Dia Juliano de la fecha de actualizacion de los datos
  66. Diario=Math.round(Datos[V]/Dias);               // Respuestas medias por dia
  67. Estimado=Diario*N_Dias;                     // Respuestas estimadas
  68. posicion=(V*(ancho+5))+10;                  // dimensiones, posicion y texto a poner en la barra grafica
  69. altura=Estimado/F_Escala;
  70. valor=Puntua(Estimado);
  71. contenido=window.document.getElementById("fondo").innerHTML;
  72. window.document.getElementById("fondo").innerHTML=contenido + "<div class=\'lila\' id=\'Previsto\' style=\'z-index: 0; bottom: 30px;\' title=\'Respuestas Previstas " +
  73.                 valor + "\'></div>";
  74. window.document.getElementById("Previsto").style.bottom=30;
  75. window.document.getElementById("Previsto").style.left=posicion;
  76. window.document.getElementById("Previsto").style.height=altura;
  77. window.document.getElementById("Previsto").style.width=ancho;
  78. contenido=window.document.getElementById("fondo").innerHTML;
  79. window.document.getElementById("fondo").innerHTML=contenido + "<span style=\'color: #000077; position: absolute; bottom:" +
  80.                 (altura+40) +"; left: " + posicion + "px;\'> Previsto<br>" + Estimado + "</span>"
  81. }

Código HTML

Código HTML:
<table>
<tr><td><h3>Titulo del Gráfico</h3>
	<p align=center id="fecha"></p></td></tr>
<tr><td>
<div id="fondo" style="top: 10px; left: 10px; height: 600px;" class="fondodiv">
<h3>Valores del Gráfico</h3>
</div>
</td></tr>
<tr><td class="pequeno"><br><b>Nota:</b> Las datos previstos se calculan en función de los datos medios del 
año hasta la fecha de actualización.</td></tr>
</table> 
grafico de barras utilizando estilos y javascript. Las barras en realidad son bloques div, cuya altura se calcula en función de los valores a representar dichos valores el puntoes Como Hago para que se muetren. la muestra la tengo pero perdi parte del codigo

Además se hace uso de una función para formatear las cifras poniendole el punto separador de los millares.

Espero Me puedan ayudar gracias de antemano

Última edición por sychowaves; 02/07/2010 a las 00:24