- D3.js 4.x Data Visualization(Third Edition)
- ?ndrew Rininsland Swizec Teller
- 264字
- 2021-07-02 23:20:26
What exactly did we do here?
The key is in the three for...each statements that we used. One loops through the array of table header strings, and appends a table cell (td) element with each value into the thead row. There are then two nested .forEach() statements that do the same for each row in the body. We technically only have one row in the body right now, so probably didn't need that messy double for...each, but now all we have to do to add another row to the table is simply append another data array to the rows variable. We'll talk more about Array.prototype.forEach and other array functions in the next chapter.
This might seem like a lot of work for such a simple table, but the advantages of doing it this way are huge. Instead of wasting a bunch of time typing out a totally static table that you'll never use again, you've effectively created a basic JavaScript library that will produce a basic table for you whenever you need it. You could even extend your tableFactory function to do different things than it does now, without ever altering the code you just wrote.
Those nested for...each loops are really ugly though. Thankfully, d3-selection provides a mechanism for adding, updating, and removing data points, which we'll get into really quickly. Instead of tracking where everything is in your project, we just need to tell D3 to manage our data and it will update any attached elements. The key part of this is selections and building functions that intelligently manipulate them.
- Cocos2d-x游戲開(kāi)發(fā):手把手教你Lua語(yǔ)言的編程方法
- Essential Angular
- Web Application Development with MEAN
- Linux操作系統(tǒng)基礎(chǔ)案例教程
- 微服務(wù)架構(gòu)深度解析:原理、實(shí)踐與進(jìn)階
- Java網(wǎng)絡(luò)編程實(shí)戰(zhàn)
- C語(yǔ)言程序設(shè)計(jì)實(shí)訓(xùn)教程與水平考試指導(dǎo)
- OpenCV 3計(jì)算機(jī)視覺(jué):Python語(yǔ)言實(shí)現(xiàn)(原書(shū)第2版)
- App Inventor少兒趣味編程動(dòng)手做
- IPython Interactive Computing and Visualization Cookbook
- Continuous Delivery and DevOps:A Quickstart Guide Second Edition
- 基于GPU加速的計(jì)算機(jī)視覺(jué)編程:使用OpenCV和CUDA實(shí)時(shí)處理復(fù)雜圖像數(shù)據(jù)
- Head First Kotlin程序設(shè)計(jì)
- RESTful Web API Design with Node.js
- C#網(wǎng)絡(luò)編程高級(jí)篇之網(wǎng)頁(yè)游戲輔助程序設(shè)計(jì)