angular

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.

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.

Related Post
  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

Recent Posts

What is the Purpose of php_eol in PHP?

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

2 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

2 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

2 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

3 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

3 months ago

Common Practices for Laravel Blade Template

in this Laravel tutorial, I will explore common practices for using the Laravel Blade template with examples. Blade is a… Read More

3 months ago

Categories