- 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).
推薦閱讀
- 深度實踐OpenStack:基于Python的OpenStack組件開發
- 零基礎學Visual C++第3版
- Reporting with Visual Studio and Crystal Reports
- Node.js 10實戰
- Android應用程序開發與典型案例
- Photoshop智能手機APP UI設計之道
- 軟件工程
- Drupal 8 Configuration Management
- 用戶體驗增長:數字化·智能化·綠色化
- Windows內核編程
- 軟件測試教程
- MINECRAFT編程:使用Python語言玩轉我的世界
- 網絡數據采集技術:Java網絡爬蟲實戰
- Android編程權威指南(第4版)
- SFML Game Development