Site icon Coding Dude

Pros and Cons for Creating Simple Pie Charts with 3 Popular JavaScript Chart Libraries

In this post I will discuss how to create a simple pie chart using 3 popular libraries: D3, Google charts and Infographic Charts library.
I will be looking at the pros and cons for pie chart created with each library.
We will try to use the libraries such that the end result looks as similar as possible and then compare the code written to get the result.

Note: This tutorial demonstrates how to create a pie chart using JavaScript, which is a client library. It is outside the scope of this tutorial to show how to create dynamic pie charts. To create dynamic charts you would need a server side component like PHP. If that is what you are interested in then I suggest first reading the post about Creating a PHP MySQL pie graph and then coming back to this tutorial.

How to create a simple pie chart with D3

D3 is a quite popular JavaScript library that does much more than charts. It is an MVC framework that has support for DOM manipulation but also for SVG. This makes it quite a nice tool for creating interactive charts. In this post we will only be looking at creating a simple piechart.

Here is the link to download & install D3 and the D3 documentation and examples.

Reasons to use D3 for charts – D3 Pros

Reasons to not use D3 for charts- D3 Cons

 

Conclusion about making a D3 pie chart: It took me a while to get my head around how D3 works and it takes a while to get used to the syntax. Also, I found it rather difficult to find my way through the huge documentation looking for a specific thing. The result looks nice a slick, however it lacks the tooltips for the slices. I could have added them but that would have added to the already long piece of code I used to create this simple D3 pie chart.

 

How to create a pie chart with Google Charts

Google charts is a library developed by Google. It has a lot of chart types and if you ever used apps from Google like Google Analytics you already saw it in action since thats how the dashboard is created. As D3 it also uses SVG to create charts.

Here is the link to download & install Google Charts and the Google Charts documentation and examples.

Reasons to use Google Charts for creating charts – Google Charts Pros

Reasons to not use Google Charts for creating charts- Google Charts Cons

 

Conclusion about making a Google Charts pie chart: The initialization of the chart and the preparation of data was a bit of trial and error until I got the hang of it. Documentation is good and it’s very nice that there are a lot of customizations that you can add to a chart. All-in-all a good impression.

How to create a pie chart with Infographic Charts and Graphs Tag library

The Infographic tags chart library is a very light weight JavaScript chart library. It uses custom HTML tags to define the charts and it uses HTML5 canvas to render them.

Here is the link to download & install Infographic Charts and Graphs Tag library and the Infographic Charts and Graphs Tag library documentation and examples.

Reasons to use Infographic Charts and Graphs Tag library for creating charts – Pros

Reasons to not use Infographic Charts and Graphs Tag library for creating charts – Cons

 

Conclusion about makinga Infographic Charts and Graphs Tag library pie chart: I honestly prefer this library over the others for creating straight forwards charts. I was just a matter of making a reference to the JavaScript file and pasting 8 lines of HTML code and the pie chart was there. So, using this library took the least amount of work, and as you can see the results are better than D3 and identical to Google Charts.

One last remark I want to make about this library is that it also has an extension built on top of it for WordPress. It’s called Charts and graphs WordPress Visual Designer and it allows visually setting up a chart right in your blog posts. This is exactly what I used for the pie chart below.

Hope you enjoyed this post about making a simple pie chart. All these are client side libraries, so they run inside the client browser. If you are interested how to hook charts to data taken from the database, here’s a nice post about making a pie chart with PHP and MySQL.

Exit mobile version