Book Image

D3.js By Example

By : Michael Heydt
Book Image

D3.js By Example

By: Michael Heydt

Overview of this book

<p>This book will take you through all the concepts of D3.js starting with the most basic ones and progressively building on them in each chapter to expand your knowledge of D3.js.</p> <p>Starting with obtaining D3.js and creating simple data bindings to non-graphical HTML elements, you will then master the creation of graphical elements from data. You’ll discover how to combine those elements into simple visualizations such as bar, line, and scatter charts, as well as more elaborate visualizations such as network diagrams, Sankey diagrams, maps, and choreopleths.</p> <p>Using practical examples provided, you will quickly get to grips with the features of D3.js and use this learning to create your own spectacular data visualizations with D3.js.</p>
Table of Contents (20 chapters)
D3.js By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
5
Using Data and Scales
Index

Preface

Learning D3.js on your own can be a daunting task. There are literally thousands of examples online with differing degrees of effective, or ineffective, explanation.

This book uses examples that take you right from the beginning, with the basic concepts of D3.js, using practical examples that progressively build on each other both within a specific chapter and also with reference to previous chapters.

We will focus on the examples created for this book as well as those found online that are excellent but could use some additional explanation. Each example will explain how the example works either line by line or by comparison with other examples and concepts learned earlier in the book.

What this book covers

Chapter 1, Getting Started with D3.js, introduces you to D3.js and building a simple application using several tools to help with its creation.

Chapter 2, Selections and Data Binding, teaches you how to use D3.js selections to create DOM elements based on data.

Chapter 3, Creating Visuals with SVG, introduces you to Scalable Vector Graphics and how to use them to render various shapes that are commonly used in D3.js visualizations.

Chapter 4, Creating a Bar Graph, demonstrates how to create a bar graph from given data.

Chapter 5, Using Data and Scales, shows you how to load data from external sources in different formats and convert it into information suitable for visualization.

Chapter 6, Creating Scatter and Bubble Plots, demonstrates how to load, scale, and plot multidimensional data in a manner that makes patterns clear to users.

Chapter 7, Creating Animated Visuals, teaches you to use animations in your D3.js applications to demonstrate how data changes over time.

Chapter 8, Adding User Interactivity, shows you how to allow users to interact with your visualizations using the mouse.

Chapter 9, Complex Shapes Using Paths, shows you how to use many of the built-in tools in D3.js to automatically generate complex paths with a few simple statements.

Chapter 10, Using Layouts to Visualize Series and Hierarchical Data, focuses on creating complex graphs that utilize the layout objects of D3.js. This includes a multitude of graphs in different categories, including stacked, packed, clustered, flow-based, hierarchical, and radial.

Chapter 11, Visualizing Information Networks, dives into demonstrating how you can use D3.js to visualize network data such as is found in social networks.

Chapter 12, Creating Maps with GeoJSON and TopoJSON, teaches you how to create maps and highlight regions on them using two forms of geographic data: Geo and TopoJSON.

Chapter 13, Combining D3.js and AngularJS, discusses how you can integrate multiple D3.js visualizations using Angular.js to create reactive visualizations.

What you need for this book

All of the tools used in this book are available on the Internet free of charge. All that is required is a modern web browser to run the samples, and all code can be edited and run online within the browser. To be specific about what makes up a modern browser, this includes Firefox, Chrome, Safari, Opera, IE9+, Android, and iOS.

Who this book is for

Whether you are new to data and data visualization, a seasoned data scientist, or a computer graphics specialist, this book will provide you with the skills you need to create web-based and interactive data visualizations. This book assumes some knowledge of coding and, in particular, experience in coding with JavaScript.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Now using the selector variable we call the .enter() function and assign it to a variable named entering."

A block of code is set as follows:

<div id='div1'>A</div>
<div id='div2'>B</div>
<div id='div3'>C</div>
<div id='div4'>D</div>
<script>
    var selector = d3.select('body')
                     .selectAll('div');
</script>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

function render(dataToRender) {
    var selector = d3.select('body')
        .selectAll('div')
        .data(dataToRender);

    var entering = selector.enter();
    entering.append('div')
        .text(function(d) { return d; });
} 

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "The value for Mikael was changed to 25."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

All examples in this text are available to review, execute, and edit online. Reference to code are referred to as a bl.ock and be referenced as follows:

This will take you to a page on http://bl.ocks.org/ for the example. This page will also contain a link to take you to jsbin.com where you can interactively make changes to the code.

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.