Book Image

Data Visualization with D3 4.x Cookbook - Second Edition

By : Nick Zhu
Book Image

Data Visualization with D3 4.x Cookbook - Second Edition

By: Nick Zhu

Overview of this book

Master D3.js and create amazing visualizations with the Data Visualization with D3 4.x Cookbook. Written by professional data engineer Nick Zhu, this D3.js cookbook features over 65 recipes. ? Solve real-world visualization problems using D3.js practical recipes ? Understand D3 fundamentals ? Includes illustrations, ready-to-go code samples and pre-built chart recipes
Table of Contents (21 chapters)
Data Visualization with D3 4.x Cookbook - Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Manipulating the raw selection


Sometimes, having access to the D3 raw selection array might be beneficial in development whether it's for debugging purposes or for integrating with other JavaScript libraries, which require access to raw DOM elements; in this recipe, we will show you ways to do that. We will also see some, internal structure of a D3 selection object.

Getting ready

Open your local copy of the following file in your web browser:

https://github.com/NickQiZhu/d3-cookbook-v2/blob/master/src/chapter2/raw-selection.html .

How to do it...

Of course, you can achieve this using the nth-child selector or the selection iterator function each, but there are cases where these options are just too cumbersome and inconvenient. This is when you might find dealing with the raw selection array a more convenient approach. In this example, we will see how the raw selection array can be accessed and leveraged:

<table class="table"> 
    <thead> 
    <tr> 
        &lt...