Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
D3.js 4.x Data Visualization

You're reading from   D3.js 4.x Data Visualization Learn to visualize your data with JavaScript

Arrow left icon
Product type Paperback
Published in Apr 2017
Publisher Packt
ISBN-13 9781787120358
Length 308 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Aendrew Rininsland Aendrew Rininsland
Author Profile Icon Aendrew Rininsland
Aendrew Rininsland
Swizec Teller Swizec Teller
Author Profile Icon Swizec Teller
Swizec Teller
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started with D3, ES2017, and Node.js FREE CHAPTER 2. A Primer on DOM, SVG, and CSS 3. Shape Primitives of D3 4. Making Data Useful 5. Defining the User Experience - Animation and Interaction 6. Hierarchical Layouts of D3 7. The Other Layouts 8. D3 on the Server with Canvas, Koa 2, and Node.js 9. Having Confidence in Your Visualizations 10. Designing Good Data Visualizations

Got mad stacks


The stack layout allows us to stack regions in a chart, which is useful for things such as stacked area charts and what have you. It's in the d3-shape package.

Go back to main.js and comment out the last example and add the following:

westerosChart.init('stack',
  'data/GoT-deaths-by-season.json', false);

We add another option to this because we're going to create two charts from this example. This time we're using our deaths-by-season dataset.

Inchapter7/index.js add the following to the bottom of the file:

westerosChart.stack = function Stack({ data }, isStream = false) { 
  const episodesPerSeason = 10; 
  const totalSeasons = 6; 
  // Create a nest containing deaths per episode
  const seasons = d3.nest() 
    .key(d => d.death.episode) 
    .key(d => d.death.season) 
    .entries(data.filter(d => !d.death.isFlashback)) 
    .map(v => { 
      return d3.range(1, totalSeasons + 1)
        .reduce((item, episodeNumber) => { 
          const deaths = v.values.filter...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime