Introduction

This blog will explain how to implement Google Combo Chart with the Angular 2+ version. I have used Angular version 7 here. NPM provides Google Charts, an open source library which is based on JavaScript. Google Charts is a graphical visualization which represents your data in the chart format.

Here are the steps to be followed in order to implement Google Combo Charts with Angular.

Step 1

Create a new project using Angular CLI. Open the command prompt and execute the following command.
  1. ng new Combo-Chart
Google Combo Chart In Angular 7

Step 2

Open the project in Visual Studio Code.
  1. cd Combo-Chart
  2. code .
Google Combo Chart In Angular 7
Step 3
Open terminal from the Terminal tab in Visual Studio Code and install Google Charts library in your project.
  1. npm install angular-google-charts
Google Combo Chart In Angular 7

Step 4

Create a google-combo-column-chart component.
  1. ng g c google-combo-chart
Google Combo Chart In Angular 7

Step 5

Open the 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 { GoogleComboChartComponent } from './google-combo-chart/google-combo-chart.component';
  7. @NgModule({
  8. declarations: [
  9. AppComponent,
  10. GoogleComboChartComponent
  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-combo-chart-compnent.ts file and add the below code.
  1. import { Component, OnInit } from '@angular/core';
  2. @Component({
  3. selector: 'app-google-combo-chart',
  4. templateUrl: './google-combo-chart.component.html',
  5. styleUrls: ['./google-combo-chart.component.css']
  6. })
  7. export class GoogleComboChartComponent implements OnInit {
  8. constructor() { }
  9. title = 'Company Hiring Report';
  10. type = 'ComboChart';
  11. data = [
  12. ["Account", 3, 2, 2.5],
  13. ["HR",2, 3, 2.5],
  14. ["IT", 1, 5, 3],
  15. ["Sales", 3, 9, 6],
  16. ["Marketing", 4, 2, 3]
  17. ];
  18. columnNames = ['Loaction','India','US','Average'];
  19. options = {
  20. hAxis: {
  21. title: 'Department'
  22. },
  23. vAxis:{
  24. title: 'Employee hired'
  25. },
  26. seriesType: 'bars',
  27. series: {2: {type: 'line'}}
  28. };
  29. width = 600;
  30. height = 400;
  31. ngOnInit() {
  32. }
  33. }
Step 7
Open the google-combo-chart-compnent.html file and add the following 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 below code.
  1. <app-google-combo-chart></app-google-combo-chart>

Step 9

Run and open your project.
  1. ng serve –open
Google Combo Chart In Angular 7
Project Output
Google Combo Chart In Angular 7