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.
Checkout other tutorial of Charting,
Chart.js
. The following required dependencies are: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>
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.
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More