Pie Chart in Angular using HighChart

In the last article, we discuss how to create a bar chart. In this article, we discuss how to create a pie chart in angular using HighChart.
Pie chart: A Pie Chart is a graph that displays the data in a circular form. The pieces of the graph are proportional to the fraction of the whole in each category. Each slice of the pie is relative to the size of that category. Let’s take one example for the pie chart we display the browser uses in the year 2020. Let’s draw the chart for the browser using in 2020.
For drawing the chart First, we need to install High chart node modules in our application.

npm install highcharts --save
npm install highcharts-angular --save

After installing module lets add a module in our app.module.ts file.

import { HighchartsChartModule } from 'highcharts-angular';
imports:      [ ..., HighchartsChartModule],

After adding a module in the app.module file we can use it in our component to draw the chart. Let’s create app.component.ts file and add import highchat module using “import * as Highcharts from ‘highcharts’;” then assign options and values to the chart in this chart we need to chart type as “Pie” and adding series data we need to pass the browser name and percentage in json format to draw the data.

import { Component, VERSION ,OnInit } from '@angular/core';
import * as Highcharts from 'highcharts';

declare var require: any;
const More = require('highcharts/highcharts-more');

const Exporting = require('highcharts/modules/exporting');

const ExportData = require('highcharts/modules/export-data');

const Accessibility = require('highcharts/modules/accessibility');

  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
export class AppComponent  implements OnInit{

 public options: any = {
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: true,
        type: 'pie'
    title: {
        text: 'Browser market shares'
    tooltip: {
        pointFormat: '{series.name}: {point.percentage:.1f}%'
    accessibility: {
        point: {
            valueSuffix: '%'
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                format: '{point.name}: {point.percentage:.1f} %'
    series: [{
        name: 'Brands',
        colorByPoint: true,
        data: [{
            name: 'Chrome',
            y: 59.41,
            sliced: true,
            selected: true
        }, {
            name: 'Internet Explorer',
            y: 11.84
        }, {
            name: 'Firefox',
            y: 11.85
        }, {
            name: 'Edge',
            y: 4.67
        }, {
            name: 'Safari',
            y: 5.18
        }, {
            name: 'Sogou Explorer',
            y: 1.64
        }, {
            name: 'Opera',
            y: 1.6
        }, {
            name: 'QQ',
            y: 1.2
        }, {
            name: 'Other',
            y: 2.61

  constructor() { }

    Highcharts.chart('container', this.options);

<h1 style="text-align:center">Pie Chart using HighChart</h1>
<div id="container"></div>

Below is the full embeded code for the pie chart using Highchart you can easily used in your application.

Spread the love