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

Interpolating a string


In some cases, you might need to interpolate numbers embedded in a string; perhaps a CSS style for font, for example.

In this recipe, we will examine how you can do that using D3 scale and interpolation. However, before we jump right into string interpolation, a bit of background knowledge on interpolator is due, and the following section will cover the basics of what interpolation is and how D3 implements interpolator functions.

Interpolator

In the first three recipes, we went over three different D3 scale implementations; now it is time to delve a little deeper into D3 scales. You are probably already asking the question, How do different scales know what value to use for different inputs? In fact, this question can be generalized through the following definition of interpolator:

We are given the values of a function f(x) at different points x0, x1, ... ,xn. We want to find approximate values of the function f(x) for "new" x's that lie between these points. This process...