简体   繁体   中英

Filtering on json import in d3js

I am learning d3js and stuck on some simple steps... I am importing json data and need to filter only data of year 2010. This is my import part:

d3.json("data/data.json").then(data => {
    data.forEach(d => {
        d.income = +d.income
        d.life_exp = +d.life_exp
        d.year = +d.year
    })
})

Where and how I need to add filtering part?

Just insert filter before forEach :

d3.json("data/data.json")
  .then(data => data
    .filter(d => d.year === 2010)
    .forEach(d => {
        ...
    })
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM