From the course: D3.js Essential Training

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Dealing with NaNs using defined()

Dealing with NaNs using defined() - D3.js Tutorial

From the course: D3.js Essential Training

Dealing with NaNs using defined()

- [Instructor] Have you ever had a single dodgy data point throw out all your code? One misformatted date, for example, or one null in thousands of numbers? It's frustrating, isn't it? Well, in this video, we're going to see how we can handle it gracefully in D3. So first of all, we have to break our data and we're going to put in a null and a string null just for fun, and refresh, and you see that we are not left with what we would hope to have. We don't have meaningful area charts representing our data. Without using defined, D3 tries to plot every point, even the broken ones, which can crush your chart or worse, make your output quite misleading. But it offers us a way round and we use it on the generator. So, this could be a d3.area generator or a line generator, and we say .defined like so. And within it, we pass the data and we say it counts as defined data if it is not throwing us a not a number error. You can write other things in here, it doesn't have to be this statement…

Contents