This tutorial will give you an example of an angular 11 bar chart example. you can optically discern angular 11 bar chart npm. we will avail you to give an example of angular 11 ng2-charts bar chart . you can visually perceive how to integrate bar charts in angular 11. Let's optically discern below the example angular 11 bar chart example.
In this example, we will utilize the ng2-charts
npm package to engender bar chart example in angular 11 application. we will simply install that ng2-charts npm package and use the ChartsModule module to engender code.
You can easily create your angular app using bellow command:
ng new myNewApp
Now in this step, we need to just install ng2-charts
in our angular application. so let's add as like bellow:
npm install ng2-charts chart.js --save
we will import ChartsModule module as like bellow code:
src/app/app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ChartsModule } from 'ng2-charts';
@NgModule({
imports: [ BrowserModule, FormsModule, ChartsModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
here, we need to update ts file as like bellow:
src/app/app.component.ts
import { Component, OnInit } from '@angular/core';
import { ChartOptions, ChartType, ChartDataSets } from 'chart.js';
import { Label } from 'ng2-charts';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
public barChartOptions: ChartOptions = {
responsive: true,
};
public barChartLabels: Label[] = ['2015', '2016', '2017', '2018', '2019', '2020'];
public barChartType: ChartType = 'bar';
public barChartLegend = true;
public barChartPlugins = [];
public barChartData: ChartDataSets[] = [
{ data: [65, 67, 70, 75, 80, 90], label: 'PHP' },
{ data: [50, 48, 47, 49, 44, 40], label: '.Net' },
{ data: [40, 30, 28, 25, 22, 20], label: 'Java' },
];
constructor() { }
ngOnInit() {
}
}
here, we need to update html file as like bellow code:
src/app/app.component.html
<h1>Angular Bar Chart Example - HackTheStuff</h1>
<div style="display: block;" >
<canvas baseChart
[datasets]="barChartData"
[labels]="barChartLabels"
[options]="barChartOptions"
[plugins]="barChartPlugins"
[legend]="barChartLegend"
[chartType]="barChartType">
</canvas>
</div>
Now you can run by bellow command:
ng serve
now you can check it.
I hope it can help you.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to get substring from a string using jQuery
Use the JavaScript substring() ...Laravel 5.5 - VueJS 2.0 CRUD Operations
Today, we are share with you VueJS 2.0 C...Laravel Ajax CRUD With yajra Datatable and Bootstrap Model Validation
In this article, we will share with you...Laravel 8 get all Files in Directory Example
You may want to get images from server a...How to Detect a Mobile Device in jQuery
Use the JS matchMedia() Method You ca...