- Expert Data Visualization
- Jos Dirksen
- 161字
- 2021-07-09 18:22:43
Grouping the loaded data so we only have the top 10 names for both sexes
At this point, we've only loaded the data. If you look back at the figure, you can see that we create a chart using the top 10 female and male names. With the following lines of code, we convert the big incoming data array to an array that contains just the top 10 female and male names:
var grouped = _.groupBy(data, 'sex');
var top10F = grouped['F'].slice(0, namesToShow);
var top10M = grouped['M'].slice(0, namesToShow);
var both = top10F.concat(top10M.reverse());
Here we use the lodash's groupBy function,to sort our data based on the sex property of each row. Next we take the first 10 (namesToShow) elements from the grouped data, and create a single array from them using the concat function. We also reverse the top10M array to make the highest boy's name appear at the bottom of the chart (as you can see when you look at the example).
推薦閱讀
- Learning Single:page Web Application Development
- Django+Vue.js商城項目實戰
- Java系統分析與架構設計
- Learn to Create WordPress Themes by Building 5 Projects
- HoloLens Beginner's Guide
- C#編程入門指南(上下冊)
- 小程序,巧運營:微信小程序運營招式大全
- C#程序設計
- Java Web程序設計任務教程
- C語言課程設計
- Learning Concurrent Programming in Scala
- Swift 4從零到精通iOS開發
- Learning Modular Java Programming
- Cocos2d-x Game Development Blueprints
- Node.js 6.x Blueprints