Add Angular Charts and Angular Graphs to your application in 60 seconds.
Your First Angular Chart
Add AG Charts to your application in these steps:
1. Install
Install the AG Charts Angular library:
npm install ag-charts-angular
yarn add ag-charts-angular
2. Import the Angular Chart
import { Component } from '@angular/core';
// Angular Chart Component
import { AgCharts } from 'ag-charts-angular';
// Chart Options Type Interface
import { AgChartOptions } from 'ag-charts-community';
3. Define Chart Data and Series
// Angular Chart Component
@Component({
selector: 'app-root',
standalone: true,
imports: [AgCharts],
template:``,
})
export class AppComponent {
// Chart Options
public chartOptions: AgChartOptions;
constructor() {
this.chartOptions = {
// Data: Data to be displayed in the chart
data: [
{ month: 'Jan', avgTemp: 2.3, iceCreamSales: 162000 },
{ month: 'Mar', avgTemp: 6.3, iceCreamSales: 302000 },
{ month: 'May', avgTemp: 16.2, iceCreamSales: 800000 },
{ month: 'Jul', avgTemp: 22.8, iceCreamSales: 1254000 },
{ month: 'Sep', avgTemp: 14.5, iceCreamSales: 950000 },
{ month: 'Nov', avgTemp: 8.9, iceCreamSales: 200000 },
],
// Series: Defines which chart type and data to use
series: [{ type: 'bar', xKey: 'month', yKey: 'iceCreamSales' }]
};
}
}
4. Angular Charts Component
Chart options are set as an ag-charts
component attribute.
template:
`<ag-charts
style="height: 100%"
[options]="chartOptions">
</ag-charts>`,
})
5. Running the Angular Chart
Below is a live example of the application running. Click </> Code
to see the code.
To live-edit the code, open the example in CodeSandbox or Plunker using the buttons to the lower-right.
Next Steps
- Read our Introductory Tutorial.