2016-12-24 4 views
0

Ich habe eine Liste im Formataus einer Liste

+---------+------------------+ 
| Country | GDP    | 
+---------+------------------+ 
| Austria | 26171.6909118266 | 
+---------+------------------+ 
| Belgium | 24512.4131357791 | 
+---------+------------------+ 
| Denmark | 32400.0606104087 | 
+---------+------------------+ 
| Spain |     | 
+---------+------------------+ 

Get Daten aus Liste:

function parseData(d) { 
    var keys = _.keys(d[0]); 
    return _.map(d, function(d) { 
    var o = {}; 
    _.each(keys, function(k) { 
     if(k == 'Country') 
     o[k] = d[k]; 
     else 
     o[k] = parseFloat(d[k]); 
    }); 
    return o; 
    }); 
} 

var xAxisOptions = ["GDP"] 
var data = parseData(data); 

d3.select('#x-axis-menu') 
.selectAll('li') 
.data(xAxisOptions) 
.enter() 
.append('li') 
.text(function(d) {return d;}) 
.classed('selected', function(d) { 
    return d === xAxis; 
}) 
.on('click', function(d) { 
    xAxis = d; 
    updateChart(); 
    updateMenus(); 
}); 

Das Problem ist, dass die ganze Zeit die gesamte Liste auswählen. Ich möchte alle BIPs bis Dänemark auswählen, hat jemand eine Idee?

+0

Haben Sie bei Dänemark beenden möchten oder Sie alle leere Werte entfernen – Rajesh

Antwort

1

Lodash ist Overkill -_-

function parseData (d) { 
    var i, cp = []; 
    for (i = 0; i < data.length; i++) { 
    if (data[i]["GDP"]) cp.push({ 
     "Country": data[i]["Country"], 
     "GDP": parseFloat(data[i]["GDP"]) 
    }); 
    } 
    return cp; 
} 
Verwandte Themen