From 0f35c49850d85b85c448617b45fe12bdfe7396e7 Mon Sep 17 00:00:00 2001 From: andrpet <andrpet@gmail.com> Date: Tue, 23 Feb 2016 10:53:01 +0100 Subject: [PATCH] number with % fix --- datalets/highcharts-datalet/highcharts-datalet.html | 59 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/datalets/highcharts-datalet/highcharts-datalet.html b/datalets/highcharts-datalet/highcharts-datalet.html index 161ed25..eb4e7ff 100755 --- a/datalets/highcharts-datalet/highcharts-datalet.html +++ b/datalets/highcharts-datalet/highcharts-datalet.html @@ -88,24 +88,26 @@ Example : /** * Normalizes a number in agreement with javascript's conventions. Delete all NaN characters. Exception: number representing lat & long remain unchanged. */ -// jNumConverter: function(num) { -// //lat-long -// if(num.charAt(num.length-7) == "." && (num.match(/[\.,]/g) || []).length == 1) -// return num; -// -// var jNum = ""; -// for (var i = 0; i < num.length; i++) { -// if(num[i].match(/[\.,]/g)) -// if (i == num.length - 3) -// jNum += "."; -// else -// ; -// else if (!isNaN(num[i])) -// jNum += num[i]; -// } -// -// return jNum; -// }, + jNumConverter: function(num) { + //lat-long + if(num.charAt(num.length-7) == "." && (num.match(/[\.,]/g) || []).length == 1) + return num; + + num = num.replace(/[^0-9\.]/, ''); + + var jNum = ""; + for (var i = 0; i < num.length; i++) { + if(num[i].match(/[\.,]/g)) + if (i == num.length - 3) + jNum += "."; + else + ; + else if (!isNaN(num[i])) + jNum += num[i]; + } + + return jNum; + }, /** * Populate the categories and the series array. * @@ -121,17 +123,16 @@ Example : for (var i = 1; i < this.data.length; i++) { - -// this.data[i].data.every(function (element, index, array) { -// try { -// var e = HighchartsBehavior.jNumConverter(element); -// (isNaN(element)) ? array[index] = parseFloat(HighchartsBehavior.jNumConverter(element)) : -// array[index] = parseFloat(element); -// }catch(e){ -// //console.log("Parsing data error. Highchart-datalet.selectData"); -// } -// return true; -// }); + this.data[i].data.every(function (element, index, array) { + try { + var e = HighchartsBehavior.jNumConverter(element); + (isNaN(element)) ? array[index] = parseFloat(HighchartsBehavior.jNumConverter(element)) : + array[index] = parseFloat(element); + }catch(e){ + //console.log("Parsing data error. Highchart-datalet.selectData"); + } + return true; + }); this.properties.series.value.push(this.data[i]); } -- libgit2 0.21.4