Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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
Mastering D3.js

You're reading from   Mastering D3.js Bring your data to life by creating and deploying complex data visualizations with D3.js

Arrow left icon
Product type Paperback
Published in Aug 2014
Publisher Packt
ISBN-13 9781783286270
Length 352 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Pablo NAVARRO CASTILLO Pablo NAVARRO CASTILLO
Author Profile Icon Pablo NAVARRO CASTILLO
Pablo NAVARRO CASTILLO
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Data Visualization FREE CHAPTER 2. Reusable Charts 3. Creating Visualizations without SVG 4. Creating a Color Picker with D3 5. Creating User Interface Elements 6. Interaction between Charts 7. Creating a Charting Package 8. Data-driven Applications 9. Creating a Dashboard 10. Creating Maps 11. Creating Advanced Maps 12. Creating a Real-time Application Index

Highlighting chart elements


We will create a simple chart depicting a series of circles that represent fruits and the number of calories we can get from 100 grams of each fruit. To make things easier, we have created a JSON file with information about the fruits. The file structure is as follows:

{
  "name": "Fruits",
  "data": [
    {
      "name": "Apple",
      "description": "The apple is the pomaceous fruit..."
      "amount_grams": 100,
      "calories": 52,
      "color": "#FF5149"
    },
    ...
  ]
}

We will represent each fruit with a circle and arrange them horizontally. We will map the area of the circle to the calories by serving, coloring them with the color indicated in the data item. As usual, we will use the reusable chart pattern, creating a closure function with the chart attributes and a charting function that contains the rendering logic, as shown in the following code:

function fruitChart() {

    // Chart Attributes
    var width = 600,
        height = 120;

    // Radius...
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 $19.99/month. Cancel anytime
Banner background image