Axis Format

90 views
Skip to first unread message

Jorge León

unread,
Jan 17, 2014, 1:46:44 PM1/17/14
to flo...@googlegroups.com
Hi,
This is no a Question, I want to share something.
I needed to change the format of the Axis, finally I did this:

1. Put a this function in my html:

<script type="text/javascript"> 
    function formato_numero(numero, decimales, separador_decimal, separador_miles){ // v2007-08-06
numero=parseFloat(numero);
if(isNaN(numero)){
return "";
}
if(decimales!==undefined){
// Redondeamos
numero=numero.toFixed(decimales);
}
// Convertimos el punto en separador_decimal
numero=numero.toString().replace(".", separador_decimal!==undefined ? separador_decimal : ",");
if(separador_miles){
// Añadimos los separadores de miles
var miles=new RegExp("(-?[0-9]+)([0-9]{3})");
while(miles.test(numero)) {
numero=numero.replace(miles, "$1" + separador_miles + "$2");
}
}
return numero;
}
</script>

2. In the yaxis I put:

tickFormatter: function(fn){
    return formato_numero(fn,0,',','.');
}

3. Ready! The Y axis has number format with decimals separator (,) and mile separator (.).

I hope dis was useful information for somebody.

Jorge
Reply all
Reply to author
Forward
0 new messages