Creating Interactive Charts in AngularJS

Data in the form of rows and columns is boring, and it’s difficult to derive insights from it in that form. Add interactive charts to it, and you make it easier for everybody to make sense of it. You start seeing patterns that were impossible to spot by looking at raw data alone. But how do you add interactive charts to your website?

Well, that’s what this tutorial will teach you. In this post I will walk you through the process of creating interactive charts in one of the most popular JavaScript frameworks – AngularJS. We will be implementing charts via FusionCharts’ JavaScript charts package. And to make our job easier, we will make use of its AngularJS charts plugin.

AngularJS makes it quite easy to create modern web apps (after the initial learning curve, of course!). And FusionCharts’ AngularJS charts plugin will let us create interactive charts with just a single directive.

With the introduction out of the way, let’s get started with the tutorial! You can also check the demo first.

View Demo

I have divided this tutorial into 4 steps:

  1. Set the dependencies
  2. Inject ng-fusioncharts module
  3. Define controller for the app
  4. Render the FusionCharts view

Step 1: Set the Dependencies

These are the three JavaScript files that we need to include:

Here’s how your HTML will look like after this step:

    <!-- AngularJS - Either include via CDN or download AngularJS and use local link -->
    <script type="text/javascript" src=""></script>
    <!-- FusionCharts Core Library JavaScript File-->
    <script type="text/javascript" src="path/to/fusioncharts.js"></script>
    <!-- FusionCharts AngularJS Plugin JavaScript File-->
    <script type="text/javascript" src="path/to/angular-fusioncharts.min.js"></script>

Step 2: Inject ng-fusioncharts Module

Next step is to include ng-fusioncharts as a dependency in our app. Below is the code to achieve that:

var app = angular.module('DemoApp', ['ng-fusioncharts']);

Step 3: Define Controller for the App

In the controller for the app, we augment the controller scope with Fusioncharts’ chart definition:

app.controller('DemoController', function($scope) {
    //chart definition
    $scope.dataSource =  '{"chart":
            "caption":"Sales - 2014 v 2015",
            "baseFont":"Helvetica Neue,Arial",
            {"seriesname":"Bakersfield Central",
            {"seriesname":"Los Angeles Topanga",

Step 4: Render the FusionCharts View

Now add the following markup to your HTML to render FusionCharts:

<div ng-controller="DemoController">
    <fusioncharts id="mychartcontainer" chartid="mychart" width="650" height="400" type="msspline" dataFormat= 'json', dataSource="{{dataSource}}" config="{{chartoptions}}">
    <!-- dataSource is data used by FusionCharts to render the chart and is declared above using $scope -->

If you have followed above steps properly and not messed up anywhere, you should see a working chart like this:

About the Guest author:

Rohit Boggarapu
Rohit Boggarapu is currently a software engineer at Adobe. He loves developing cool things and writing for the web. When not writing code, you will find him either practicing Yoga, or talking about it. He is always up for a quick chat on Twitter.

8 Responses

  1. FH says:

    Demo chart won’t load

  2. dyo says:

    how to get this file ?


  3. abiya says:

    Very nice post here thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information’s.

  4. Is there any freelancers you would recommend for doing this type of coding?

  5. I have a client looking to integrate charts onto his site. I am looking to get steered in the right direction.

  6. Eric says:

    Where can I find the html that you used to get this working?

  7. sameer says:

    Check the demo link at the bottom of the post, which also gives the code.