3 min read
Displaying your data as graphs and charts not only make them more easy to understand, it also makes dealing with data not so boring. As a web developer / programmer you either worked with or going to work with data. Chart.js and D3.js are the two most popular data visualization libraries that you can use with JavaScript. In this post I am going to be sharing with you some general information about each of them and my personal opinion using both of these libraries.
As web developers it's up to us to evaluate the needs of a each project and choose the right tools that we will use. For this very purpose it's very important to experiment using different libraries, frameworks and softwares every now and then.
First of all even though there are differences between these two data visualisation libraries, they serve the very same purpose. Both Chart.js and D3.js have various examples for multiple usecases and types of data. They are both popular enough so if you run into trouble while trying to create a chart you can be sure that there will be other programmers to help you out.
Ok, first of all I have to include that as a freeCodeCamp alumni D3.js was the first first data visualisation library I was introduced to. Learning curve might be a little steep but now I I know that it's worth pushing through that pain.
D3.js is a very diverse and powerful library when it comes to creating charts that serve a spesific (and even odd) need. The sheer amount of examples I'm sure will blow you away. There are some very creative people out there!
With d3.js you will be a ble to easily append (add), remove and update SVG elements (on which d3.js actually creates the chart) on DOM. You can animate your charts and make them interactive as well in order to provide an easier digest the information you are presenting. D3.js will help you when you need to work with geographical data. You can easily create a map with and display you data in an interactive way.
For a very recent project, that actually motivated me to write this post, I had to create simple a multi-line chart quickly. So I decided to give Chart.js a try. I was and still am very impressed with how little it took and to create simple charts and graphs that was reponsive, animated and interactive. The charts include a pop-up that activates on hover, a legend.
The configurations are very easy to grasp as well. You will have no trouble changing the colors, widths or sizes inside the chart. Instead of a SVG Chart.js uses a Canvas element to render the content into.
Both libraries have their weaknesses and strengths. If you need a simple chart that works and looks well out of the box with minimal configuration you should go with Chart.js. But if you need a more spesific chart or you want to visualize data on a map D3.js is the library for you.
You can guess why more experinced developers prefer using D3.js over Chart.js. When the complexity is not a huge problem you might as well go with a tool that requires more configuration. More configuration means more work but at the same time you will be creating just the visualisation you have in mind that looks pixel perfect and suits your projects' needs.
Of course, not all the charts you need to create are complex. Sometimes you just need to create a simple chart that just looks good with close to no configuration.With chart.js I was able to create the chart necessary in 5 minutes whereas with d3.js achieving the same result would defeinitely take longer.
Well there you go, this was my opinion on the two most popular data visualisation libraries you can use in your websites. Hope you found some value in this post. Keep on learning !
Ilker AkbiyikTable of Contents