For the best experience, try the new Microsoft Edge browser recommended by Microsoft (version 87 or above) or switch to another browser � Google Chrome / Firefox / Safari
OK

In this post I give you an overview of JavaScript library D3, here I won't compare D3 to other charting libraries but in some instances I will refer to popular technologies like jQuery and jQueryUI since it is very easy to understand where you stand compared to what you probably already know.

What is D3?

One can say D3 is a JavaScript library that "helps" you in creating "visualizations". Let me explain the above statement a bit. I say "helps" because unlike other charting or UI libraries, it does not take a set of parameters and create a UI for you. The job of D3 is that it takes your data and either modifies it in such a way that it attaches helping keys in the data or provides you with functions that will use the data (that you give it) to provide you with output.

What can I do with D3 that I cannot do using other libraries?

D3 has a list of layouts that you can use to create your visualizations. Think of each layout as a function that takes data and modifies it in a way so as to create that layout. For example, consider the TreeMap layout, it'd take an object in the hierarchical format and append keys like 'x', 'y', 'dx' and 'dy' to it. Using these keys you can position elements on the page and give them dimensions so as to view the data that you have sent in the first place in the form of a TreeMap. Another interesting example of visualization is creating a geographical map. D3 has the d3.geo API which takes actual coordinates of regions/countries and plots them using different layouts. You can have flat (Mercator) maps as well as spherical (Orthographic) maps and many more in between. Unlike other libraries, D3 (in most cases) doesn't create the HTML or UI for you. It does the difficult part that is of the calculations and leaves appending DOM elements to you. The main advantage of this is the flexibility of choosing which HTML/SVG elements. For example in the TreeMap example above, you have the flexibility of using divs or svg elements for rendering the TreeMap.

Advantages of D3

Flexibility is one of the biggest advantages of D3. The fact that it does most of the calculation and lets you handle what and what not to append to the DOM can be very powerful. You'll not have to bother finding a way to show multiple axes, to hide ticks when you don't want them, and the like. The choice of selecting the type(like svg over div) of elements to use is another big advantage. The large span of functionality that D3 provides viz. time, scales, layouts, geography, geometry, interactions, transitions, SVG, and other helper functions to do number crunching on your data is also impressive.

Limitations of D3

In my personal opinion, the learning curve of D3 is a bit steep. I won't say it is difficult but it is different. It introduces new (at least for me) concepts like virtual joins. And the JavaScript part is also bit confusing to understand (at first) as it uses a declarative programming style over the conventional imperative one. But once you understand how to wield it, it is a power you can't code without! Flexibility which is one of its advantages itself proves to be a pitfall if you don't use it responsibly. Since you are given the flexibility to choose your own DOM elements, it is very easy to get carried away. For instance, while using svg elements, you have to keep a check on the number of elements that you append to the DOM. The performance of SVG depends a lot on the number of elements in the DOM. And we are not just talking about displaying charts and visualizations. We are talking about interacting with them.

Conclusion

D3 provides a huge span of functionality in the visualization sector. With cons which exist only if one lets them come. In my opinion it is a tool that all UI developers should carry under their belt.

Get Started

Your Information

1 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Your Information

12 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Your Information

4 + 12 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
Globally Presence
Across Americas, Europe, and Asia
All Locations
Asia
Europe
North America
19 Locations
7
10
2
10 Locations
Ahmedabad
A-201, WestGate Business Bay, SG Road, Makarba, Ahmedabad 380015
Hyderabad
Block –B, Wing 1, 2nd Floor, Cyber Gateway, Hitech city, Hyderabad 500081
Gurugram
2nd Floor, Tower B, Unitech Cyber Park, Sector 39, Gurugram 122001
Singapore
70 Shenton Way, #13-03, Eon Shenton, Singapore 079118
Bengaluru
Subramanya Arcade SA Tower, 2nd floor, A-wing, Bannerghatta Main Road, BTM Layout, Bengaluru, Karnataka 560029
Chennai
8th Floor, Smartworks, Olympia National Tower, Block 3, A3 and A4, North Phase, Guindy Industrial Estate, Chennai 600032
Pune
7th Floor, IT-7 Building, Qubix Business Park Pvt. Ltd. SEZ, Phase - 1, Hinjawadi, Pune 411057
Mumbai - Thane
AWFIS 1st Floor, Nehru Nagar, Wagle Industrial Estate, Thane West, Thane Maharashtra 400604
Mumbai
7th Floor, Smartworks, Times Square, Tower C, Andheri Kurla Road, Marol, Andheri East, Mumbai 400059
Pune
6th Floor, Smartworks, Pan Card Club Road, Baner, Pune 411045
2 Locations
London
c/o SPACES, 12 Hammersmith Grove, London W67AP, UK
Ireland
Grove, Fethard, Co. Tipperary, E91 E282, Dublin, Ireland
7 Locations
Canada
55 York Street, Suite 401 Toronto, ON, Canada M5J 1R7
Mexico
Tomas A. Edison 1510-201 Ciudad Juárez, Chihuahua, Mexico 32300
Seattle
4030 Lake Wash Blvd NE, STE 210, Kirkland, WA 98033
Troy
6915 Rochester Road Suite 300 Troy, MI 48085
Sunnyvale
1248 Reamwood Avenue Sunnyvale, CA 94089
New Jersey
343 Thornall Street Suite 720 Edison, NJ 08837
Dallas
5851 Legacy Circle Suite 600 Plano, TX 75024
All Locations
19 Locations
7
10
2
10 Locations
Ahmedabad
A-201, WestGate Business Bay, SG Road, Makarba, Ahmedabad 380015
Hyderabad
Block –B, Wing 1, 2nd Floor, Cyber Gateway, Hitech city, Hyderabad 500081
Gurugram
2nd Floor, Tower B, Unitech Cyber Park, Sector 39, Gurugram 122001
Singapore
70 Shenton Way, #13-03, Eon Shenton, Singapore 079118
Bengaluru
Subramanya Arcade SA Tower, 2nd floor, A-wing, Bannerghatta Main Road, BTM Layout, Bengaluru, Karnataka 560029
Chennai
8th Floor, Smartworks, Olympia National Tower, Block 3, A3 and A4, North Phase, Guindy Industrial Estate, Chennai 600032
Pune
7th Floor, IT-7 Building, Qubix Business Park Pvt. Ltd. SEZ, Phase - 1, Hinjawadi, Pune 411057
Mumbai - Thane
AWFIS 1st Floor, Nehru Nagar, Wagle Industrial Estate, Thane West, Thane Maharashtra 400604
Mumbai
7th Floor, Smartworks, Times Square, Tower C, Andheri Kurla Road, Marol, Andheri East, Mumbai 400059
Pune
6th Floor, Smartworks, Pan Card Club Road, Baner, Pune 411045
2 Locations
London
c/o SPACES, 12 Hammersmith Grove, London W67AP, UK
Ireland
Grove, Fethard, Co. Tipperary, E91 E282, Dublin, Ireland
7 Locations
Canada
55 York Street, Suite 401 Toronto, ON, Canada M5J 1R7
Mexico
Tomas A. Edison 1510-201 Ciudad Juárez, Chihuahua, Mexico 32300
Seattle
4030 Lake Wash Blvd NE, STE 210, Kirkland, WA 98033
Troy
6915 Rochester Road Suite 300 Troy, MI 48085
Sunnyvale
1248 Reamwood Avenue Sunnyvale, CA 94089
New Jersey
343 Thornall Street Suite 720 Edison, NJ 08837
Dallas
5851 Legacy Circle Suite 600 Plano, TX 75024