Gian Gian - 3 months ago 20
Javascript Question

javascript float data

Given myData is JSON var as follow:

({0:{qID:"3", id:"1", shortText:"Leisure", OpiCount:"0"},
1:{qID:"3", id:"2", shortText:"Business", OpiCount:"3"},
2:{qID:"3", id:"3", shortText:"University visit", OpiCount:"1"}, length:3})


To transform into float data array:

var data = [];
myData.each(function(i,v) {
data[i] = { label: v.shortText, data: v.OpiCount } ;
})


The above code break because of the white space in
v.shortText
. How can I overcome this?

Answer

Thanks for #Jan and #diEcho, I have figured out.

my problem is flot needs numeric data. Just add parseFloat(v.OpiCount)

var data = [];
myData.each(function(i,v) {  
    data[i] = { label: v.shortText, data: parseFloat(v.OpiCount) } ; 
})

Regards.