Simple Demo and Example of PIE Chart in AngularJS Using ChartJS

In this post i will let you know how to show PIE chart in angular application using angular-chart.js chart library.This chart library is angular version of JavaScript chart.js library.You can download angular charts library from Here .

Angular Charts is a HTML5 based charting library which is creating chart on canvas html5 element.Angular Charts is lightweight and popular charting library in JavaScript.The main features of angular_chart.js are responsive, Reactive and html5 supported Chart library.You can create beautiful charts for AngularJS using Chart.js library.

pie-charts-angularjs-demo

Checkout other tutorial of Charting,

Angular-chart is a native AngularJS directives for Chart.js. The following required dependencies are:

  • AngularJS (tested with 1.2.x, 1.3.x and 1.4.x although it probably works with older versions)
  • Chart.js (requires Chart.js 1.0, tested with version 1.0.1 and 1.0.2).

Step 1: Included all dependency files of angular charts.

  <script src="/angular/angular.min.js"></script>
  <script src="/Chart.js/Chart.min.js"></script>
  <script src="/angular-chart.js/dist/angular-chart.min.js"></script>
   	 	 	 	 	<link rel="stylesheet" href="/angular-chart.js/dist/angular-chart.css">

Step 2: inject dependency in angular module.

  angular.module("testapp", ["chart.js"])

Step 3: Define Data an labels for PIE charts.We need to assigned all labels in chartLabels array and data into chartData JavaScript array,Please make sure labels and datas series will not mismatch.

  $scope.chartLabels = ['Series A', 'Series B', 'Series C'];
  $scope.chartData = [65, 59, 20];

Step 4: Define Chart directory in HTML file and assigned model to it.

  <canvas id="pie" class="chart chart-pie" chart-data="chartData" chart-labels="labelsArr" legend="true">
				</canvas>

How To get value of clicked slice in PIE chart

Sometimes we need to preform some operation on click of PIE chart slice, so below code will help to get clickes slice value of PIE chart.

chart-click="onClickSlice"
$scope.onClickSlice = function (points, evt) {
          console.log(points);
        };

charts.js provides onClickSlice="" callback method which is fired when PIE chart clicked and get slice value.

Download Code and Demo Link

Leave a Reply

Your email address will not be published. Required fields are marked *