This article will demonstrate how to create charts using Highcharts Library in Angular JS with Web API.
We already know that DotNet Highcharts library is a client-side library for charting and we can create very clean and flexible charts with minimum configuration. Using Highcharts, we can create probably all types of charts which we use in daily life, it could be a line chart, it could be a bar chart or even a column chart.
Charts must be a reusable component in any application so that we can reuse it at different places. That’s why here, we are creating a generic custom directive in AngularJS for charts, which will render different types of charts based on the type of the chart.
In this demonstration, we will use SQL Server for data storage which will be fetched by Web API. At client-side, we are using AngularJS where service fetches the data from API and share with Custom Directive which will responsible to render charts.
This demonstration will cover up three different topics and it seems that if we cover up all topics in single article that will be very long and boring. So, we will divide it in three different parts as following.
- Part 1: Create charts using Highcharts Library and AngularJS custom directive with Web API
- Part 2: Implement Drilldown functionality with charts [Nested charts]
- Part 3: Show loading image/message when rendering the charts
So, let’s move to practical implementation of PART 1 and create charts. To complete this demonstration, there are several tasks which need to be completed.
- TASK 1: Create Database, tables and insert scripts in SQL Server.
- TASK 2: Create Asp.Net MVC application with Web API
- TASK 3: Add Ado.Net Entity Data Model to fetch data from server in API
- TASK 4: Create client side application using Angular JS and implement Highcharts
- TASK 5: Create services and controller to fetch data from API
- TASK 6: Create generic custom directive to render charts
Above is the objective of this article which will be covered step by step as following.
TASK 1 - Create Database tables and insert scripts in SQL Server.Open SQL Server Management Studio and create a database named “Summit” as well as, two more tables named “Batsmen” and “BatsmenRuns”. These tables will store the data about Top Indian Batsmen’s runs. So, just execute the following scripts to create these two tables and their data.
- CREATE DATABASE Summit
- Go
- USE Summit
- --Table which will store the total scored runs by top india batsmen
- CREATE TABLE Batsmen (ID INT PRIMARY KEY IDENTITY(1,1), Name VARCHAR(255) NOT NULL, TotalMatches INT NOT NULL, TotalRuns INT NOT NULL)
- INSERT INTO Batsmen (Name,TotalMatches,TotalRuns) VALUES('Sachin Tendulkar',463, 18426);
- INSERT INTO Batsmen (Name,TotalMatches,TotalRuns) VALUES('Yuvraj Singh', 304, 8701 );
- INSERT INTO Batsmen (Name,TotalMatches,TotalRuns) VALUES('M S Dhoni', 306, 9758 );
- INSERT INTO Batsmen (Name,TotalMatches,TotalRuns) VALUES('Rahul Dravid',344, 10889 );
- INSERT INTO Batsmen (Name,TotalMatches,TotalRuns) VALUES('Sourav Ganguly',311, 11363 );
- INSERT INTO Batsmen (Name,TotalMatches,TotalRuns) VALUES('Virender Sehwag',251, 8273);
- --Table which will store the scored runs in respective years
- CREATE TABLE BatsmenRuns (ID INT PRIMARY KEY IDENTITY(1,1), Name VARCHAR(255) NOT NULL, Year INT NOT NULL, Runs INT NOT NULL)
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',1989, 0 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',1990, 239 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',1991, 417 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',1992, 704 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',1993, 319 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',1994, 108 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',1995, 444 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',1996, 161 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',1997, 101 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',1998, 189 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',1999, 843 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2000, 132 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2001, 904 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2002, 741 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2003, 114 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2004, 812 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2005, 412 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2006, 628 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2007, 142 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2008, 460 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2009, 972 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2010, 204 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2011, 513 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sachin Tendulkar',2012, 315 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2000,260 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2001,238 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2002,659 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2003,600 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2004,841 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2005,839 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2006,849 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2007,1287)
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2008,893 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2009,783 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2010,349 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2011,453 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2012,2 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2013,276 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Yuvraj Singh',2017,372 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2004,19 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2005,895 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2006,821 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2007,1103);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2008,1097);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2009,1198);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2010,600 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2011,764 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2012,524 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2013,753 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2014,418 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2015,640 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2016,278 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('M S Dhoni',2017,648 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',1996,475 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',1997,951 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',1998,283 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',1999,1761);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',2000,980 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',2001,740 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',2002,913 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',2003,623 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',2004,1025);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',2005,1092);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',2006,919 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',2007,823 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',2009,180 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Rahul Dravid',2011,124 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',1992, 3 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',1996, 269 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',1997, 1338);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',1998, 1328);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',1999, 1767);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',2000, 1579);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',2001, 813 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',2002, 1114 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',2003, 756 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',2004, 947 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',2005, 209 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Sourav Ganguly',2007, 1240 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',1999, 1 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2000, 19 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2001, 439 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2002, 1130);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2003, 871 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2004, 671 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2005, 1017);
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2006, 608 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2007, 475 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2008, 893 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2009, 810 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2010, 446 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2011, 645 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2012, 217 );
- INSERT INTO BatsmenRuns (Name,Year,Runs) VALUES('Virender Sehwag',2013, 31 );









Mohammad SowravPosted Aug 11, 2021, 3:04 AM
Thank you so much, sir. It working.
Aniket NarvankarPosted Jul 12, 2020, 7:00 AM
I forgot to add reference of jquery. Very good article for beginners. I am implementing this in my project
Aniket NarvankarPosted Jul 12, 2020, 6:59 AM
Hi Sir,Chart Rendered with data
Aniket NarvankarPosted Jul 12, 2020, 6:49 AM
Which version of jquery we need to use?
Aniket NarvankarPosted Jul 12, 2020, 6:03 AM
Hi Sir,not working getting error in highchart.js and drilldown.js
PSD Achyut BabuPosted Feb 13, 2018, 3:45 AM
Also when i debug i didn't see any request under CricketController. Did we miss somethig in the registration?
PSD Achyut BabuPosted Feb 13, 2018, 1:42 AM
Hi mukesh, your articles are very useful to quickly try new learnings. In this article i tried all the steps but the chart is not rendered with no error. Kindly advise