I have implemented Google Charts with the Angular 7 version. NPM provides a Google Charts library which is based on JavaScript. It is an open source library to use for your web applications. Google Charts is a graphical visualization to represent your data in the chart format.

Implementing Google Charts with Angular 7

Here are the steps to be followed.

Step 1

Create a new project using Angular CLI. Open the command prompt and type the following command.
  1. ng new column-chart
Different Way Of Implementing Google Column Chart In Angular 7

Step 2

Open this project in Visual Studio Code.
  1. cd column-chart
  2. code .
Different Way Of Implementing Google Column Chart In Angular 7
Step 3
Open terminal from the Terminal tab in VS Code and install the Google Charts library in your project.
  1. npm install angular-google-charts
Different Way Of Implementing Google Column Chart In Angular 7
Step 4
Create a component named google-column-chart.
  1. ng g c google-column-chart
Different Way Of Implementing Google Column Chart In Angular 7

Step 5

Open app-module.ts and import Google Charts.
  1. import { BrowserModule } from '@angular/platform-browser';
  2. import { NgModule } from '@angular/core';
  3. import { GoogleChartsModule } from 'angular-google-charts';
  4. import { AppRoutingModule } from './app-routing.module';
  5. import { AppComponent } from './app.component';
  6. import { GoogleColumnChartComponent } from './google-column-chart/google-column-chart.component';
  7. @NgModule({
  8. declarations: [
  9. AppComponent,
  10. GoogleColumnChartComponent
  11. ],
  12. imports: [
  13. BrowserModule,
  14. AppRoutingModule,
  15. GoogleChartsModule
  16. ],
  17. providers: [],
  18. bootstrap: [AppComponent]
  19. })
  20. export class AppModule { }

Step 6

Open the google-column-chart-compnent.ts file and add the below code.
  1. import { Component, OnInit } from '@angular/core';
  2. @Component({
  3. selector: 'app-google-column-chart',
  4. templateUrl: './google-column-chart.component.html',
  5. styleUrls: ['./google-column-chart.component.css']
  6. })
  7. export class GoogleColumnChartComponent implements OnInit {
  8. constructor() { }
  9. title = 'Company Hiring Report';
  10. type = 'ColumnChart';
  11. data = [
  12. ["2014", 200],
  13. ["2015", 560],
  14. ["2016", 280],
  15. ["2017", 300],
  16. ["2018", 600]
  17. ];
  18. columnNames = ['Year', 'India'];
  19. options = {};
  20. width = 600;
  21. height = 400;
  22. ngOnInit() {
  23. }
  24. }

Step 7

Open the google-chart-compnent.html file and add this code.
  1. <google-chart #chart
  2. [title]="title"
  3. [type]="type"
  4. [data]="data"
  5. [columnNames]="columnNames"
  6. [options]="options"
  7. [width]="width"
  8. [height]="height">
  9. </google-chart>

Step 8

Open the app-compnent.html file and add the following code.
  1. <app-google-column-chart></app-google-column-chart>

Step 9

Run and open your project.

ng serve –open

Different Way Of Implementing Google Column Chart In Angular 7

Project Output

Different Way Of Implementing Google Column Chart In Angular 7

Grouped Column Chart

  1. import { Component, OnInit } from '@angular/core';
  2. @Component({
  3. selector: 'app-google-column-chart',
  4. templateUrl: './google-column-chart.component.html',
  5. styleUrls: ['./google-column-chart.component.css']
  6. })
  7. export class GoogleColumnChartComponent implements OnInit {
  8. constructor() { }
  9. title = 'Company Hiring Report';
  10. type = 'ColumnChart';
  11. data = [
  12. ["2014", 500, 200],
  13. ["2015", 430, 560],
  14. ["2016", 600, 200],
  15. ["2017", 150, 400],
  16. ["2018", 700, 480]
  17. ];
  18. columnNames = ['Year', 'India','USA'];
  19. options = {};
  20. width = 600;
  21. height = 400;
  22. ngOnInit() {
  23. }
  24. }
Different Way Of Implementing Google Column Chart In Angular 7
Stacked Column Chart
  1. import { Component, OnInit } from '@angular/core';
  2. @Component({
  3. selector: 'app-google-column-chart',
  4. templateUrl: './google-column-chart.component.html',
  5. styleUrls: ['./google-column-chart.component.css']
  6. })
  7. export class GoogleColumnChartComponent implements OnInit {
  8. constructor() { }
  9. title = 'Company Hiring Report';
  10. type = 'ColumnChart';
  11. data = [
  12. ["2014", 500, 200],
  13. ["2015", 430, 560],
  14. ["2016", 600, 200],
  15. ["2017", 150, 400],
  16. ["2018", 700, 480]
  17. ];
  18. columnNames = ['Year', 'India','USA'];
  19. options = {
  20. hAxis: {
  21. title: 'Year'
  22. },
  23. vAxis:{
  24. minValue:0
  25. },
  26. isStacked:true
  27. };
  28. width = 600;
  29. height = 400;
  30. ngOnInit() {
  31. }
  32. }
Different Way Of Implementing Google Column Chart In Angular 7
Negative Stacked Column
  1. import { Component, OnInit } from '@angular/core';
  2. @Component({
  3. selector: 'app-google-column-chart',
  4. templateUrl: './google-column-chart.component.html',
  5. styleUrls: ['./google-column-chart.component.css']
  6. })
  7. export class GoogleColumnChartComponent implements OnInit {
  8. constructor() { }
  9. title = 'Company Hiring and Firing Report';
  10. type = 'ColumnChart';
  11. data = [
  12. ["2014", 500, 200],
  13. ["2015", -90, 560],
  14. ["2016", 600, 150],
  15. ["2017", 250, -100],
  16. ["2018", -180, 480]
  17. ];
  18. columnNames = ['Year', 'India','USA'];
  19. options = {
  20. hAxis: {
  21. title: 'Year'
  22. },
  23. vAxis:{
  24. minValue:0
  25. },
  26. isStacked:true
  27. };
  28. width = 600;
  29. height = 400;
  30. ngOnInit() {
  31. }
  32. }
Different Way Of Implementing Google Column Chart In Angular 7