Posted at

D3.jsで外部ファイル読み時の型変換

More than 1 year has passed since last update.

数値に変換する

//型変換

var cast = function(d){
Object.keys(d).forEach(function(key){
if (!isNaN(+d[key])) d[key] = +d[key]
})

return d
}

d3.json("hoge.json", cast , main)

function main(data){
console.log(data)
}