Book Image

D3.js 4.x Data Visualization - Third Edition

By : Aendrew Rininsland, Swizec Teller
Book Image

D3.js 4.x Data Visualization - Third Edition

By: Aendrew Rininsland, Swizec Teller

Overview of this book

Want to get started with impressive interactive visualizations and implement them in your daily tasks? This book offers the perfect solution-D3.js. It has emerged as the most popular tool for data visualization. This book will teach you how to implement the features of the latest version of D3 while writing JavaScript using the newest tools and technique You will start by setting up the D3 environment and making your first basic bar chart. You will then build stunning SVG and Canvas-based data visualizations while writing testable, extensible code,as accurate and informative as it is visually stimulating. Step-by-step examples walk you through creating, integrating, and debugging different types of visualization and will have you building basic visualizations (such as bar, line, and scatter graphs) in no time. By the end of this book, you will have mastered the techniques necessary to successfully visualize data and will be ready to use D3 to transform any data into an engaging and sophisticated visualization.
Table of Contents (18 chapters)
Title Page
About the Authors
About the Author2
About the Reviewer
Customer Feedback
Shape Primitives of D3

Rendering in Canvas on the server

How about we do another one of those things right now? As mentioned before, the output from our little server app is pretty dull. Let's render a map using Canvas.

We haven't really talked about it much, but Canvas is another cool way D3 can be used to render data. Instead of writing a bunch of elements into a DOM tree format like SVG, Canvas renders pixels in a 2D plane, which can be much better for performance. It's a much different workflow than what we're used to, and I don't focus on it too much in this book because it tends to be harder to debug for beginners, but let's give it a shot and deep dive into it for one example.

By the way, it's worth noting this is a super weird way to use Canvas compared to how we can in the browser; normally, we'd just rely on the browser's built-in Canvas renderer, but we don't have that luxury on the server. Note, however, that the Canvas code we're writing for node-canvas will work the same way in the browser, in case...