How To Render Charts Using Aurelia And FusionCharts

Aurelia is a JavaScript client framework for mobile, desktop and web which helps in developing applications. The application can be a collection of modern javascript modules and with MV architecture it can be used with business logic.

Using Aurelia framework, you can create rich dynamic data-driven UI composition with a two-way data binding feature and integrated test table modules.

In this tutorial, we will learn how you can render charts in Aurelia framework. To render charts using Aurelia framework, we’ll use FusionCharts JavaScript Library.

Requirements

Before you start, make sure you have the following components on your local machine:

To render charts in Aurelia framework, refer to the step by step process given below:

Setting up the Environment

Install Aurelia in your local system. Run the following code in the terminal:
npm install aurelia-cli -g

After the installation, create the skeleton of the application. Run the following code in cmd shell to create the skeleton :
au startThe above command will install all the dependencies to run a basic project.

Install FusionCharts library by running the following command on the terminal.
npm install fusioncharts

To know more about how to install FusionCharts via npm check here.

Configuring the chart

Open the project in a text editor and open aurelia.json file. In this file, search for a prepend array of objects and add node_modules path to it. Refer to the code snippet below:

Import FusionCharts library files in your project. To do this, browse app.js file located inside the src folder of your project and add the following lines to it:

Now, create a datasource object and place them inside the FusionCharts constructor method. To do so, implement the Aurelia’s attached method of the component lifecycle. To know more about Aurelia’s component life cycle, click here. Refer to the following code snippet.

Following is the entire code present in app.js file:

Rendering the Chart

Now that we have our code in place, let us run the code to see the output.

Run the following command from the shell interface.
au run --watch

The output should be as shown in the image below:

If you see any errors in your code, you can download the complete source code of the sample project.

Leave a Comment