Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/02/2014, 04:43
Macijauskas
 
Fecha de Ingreso: octubre-2009
Mensajes: 7
Antigüedad: 15 años, 4 meses
Puntos: 0
Illegal Characters

Hola,

Tengo un pequeño problemita. Espero podais orientarme.

Estoy utilizando google charts en un .xml. ( https://developers.google.com/chart/?hl=es).

Como el javascript que utiliza me choca con otra librería de java tengo que insertar esta linea de código.
Código:
 Array.prototype.reduce=function(fun){var len=this.length>>>0;if(typeof fun!="function")throw new TypeError;if(len==0&&arguments.length==1)throw new TypeError;var i=0;if(arguments.length>=2)var rv=arguments[1];else{do{if(i in this){var rv=this[i++];break}if(++i>=len)throw new TypeError;}while(true)}for(;i<len;i++)if(i in this)rv=fun.call(undefined,rv,this[i],i,this);return rv};
Me compila correctamente, pero a la hora de ejecutar el javascript, me da error. Illegal Character. Con el Firegug, meto el código traducido:

Código:
Array.prototype.reduce=function(fun){var len=this.length>>>0;if(typeof fun!="function")throw new TypeError;if(len == 0 && arguments.length==1)throw new TypeError;var i=0;if(arguments.length>=2)var rv=arguments[1];else{do{if(i in this){var rv=this[i++];break}if(++i>=len)throw new TypeError;}while(true)}for(;i<len;i++)if(i in this)rv=fun.call(undefined,rv,this[i],i,this);return rv};
Así me pinta. Pero si dejo ese código en eclipse vuelve a darme error cuando ejecuta. He probado a introducir el CDATA y tampoco funciona. No me reconoce los caracters.

¿Alguna idea?

El código entero es este.

Código:
 
<script type="text/javascript" id="test">
						    
							function drawCharts(){
								 var whatever = Array.prototype.reduce;
								try {
									<![CDATA[											
									Array.prototype.reduce=function(fun){var len=this.length>>>0;if(typeof fun!="function")throw new TypeError;if(len==0&&arguments.length==1)throw new TypeError;var i=0;if(arguments.length>=2)var rv=arguments[1];else{do{if(i in this){var rv=this[i++];break}if(++i>=len)throw new TypeError;}while(true)}for(;i<len;i++)if(i in this)rv=fun.call(undefined,rv,this[i],i,this);return rv};
									//Array.prototype.reduce=function(fun){var len=this.length>>>0;if(typeof fun!="function")throw new TypeError;if(len == 0 && arguments.length==1)throw new TypeError;var i=0;if(arguments.length>=2)var rv=arguments[1];else{do{if(i in this){var rv=this[i++];break}if(++i>=len)throw new TypeError;}while(true)}for(;i<len;i++)if(i in this)rv=fun.call(undefined,rv,this[i],i,this);return rv};					
									]]>
									var data = new google.visualization.DataTable();
									data.addColumn('string', 'Mes');
									data.addColumn('number', 'a');data.addColumn('number', 'Extras');data.addColumn('number', 'B'); data.addColumn('number', 'C');data.addColumn('number', 'D');
									
												
									var options = {
											chartArea:{left:30,right:5,top:15,width:"90%",height:"60%"},									       
									        legend: { position: 'top', maxLines: 12 },
									        tooltip: {isHtml: true},
										bar: { groupWidth: '75%' },
									        isStacked: true,
									      };
									var chart = new google.visualization.ColumnChart(document.getElementById('payroll_chart_div'));
									chart.draw(data, options);
								} finally {
									Array.prototype.reduce = whatever;			
								}
							}
							google.load("visualization", "1", {'callback' : 'drawCharts' ,'packages':["corechart"], 'language': 'en'});
							
						</script>
Muchas gracias.