---
title: "Create a Basic Chart"
framework: angular
version: "14.1.0"
---

# Create a Basic Chart

Learn the key concepts of AG Charts by building a basic combination chart and applying styling & formatting

[Get Started](https://www.youtube.com/watch?v=uPN1f2ItXr8)

## Overview

In this tutorial you will:

1. [Create a Simple Bar chart](#chart-basics)
2. [Add an additional Line Series to the Bar Series](#combination-charts)
3. [Style the chart with Themes, titles, Legend, and formatted data](#styling)
4. [Format the axes](#formatting-axes)

By the end of this tutorial, you will have a Line and Bar combination chart, with a Legend, title and formatted values. Try it out for yourself by hovering elements to display tooltips, or toggling series visibility by clicking the Legend elements in the example below.

#### Complete Formatted Example

```ts
// Angular entry point file
import '@angular/compiler';
import { bootstrapApplication } from '@angular/platform-browser';

import { AppComponent } from './app.component';

bootstrapApplication(AppComponent);
```

[Live example: Complete Formatted Example](https://www.ag-grid.com/charts/angular/create-a-basic-chart/examples/complete-formatted-example)

## Chart Basics

Complete our [Quick Start](https://www.ag-grid.com/charts/angular/quick-start/) (or open the example below in Plunker) to start with a basic chart, comprised of:

- **Chart Options:** Object which contains the chart configuration options, including **data**, and **series** properties:
  - **data:** The data to display within a chart (*typically* an array of data-points).
  - **series:** The type of chart to display, and the data to use. For cartesian charts, a minimum of three properties are required:
    - **type:** Defines the type of chart to display (e.g. Line, Bar, etc.).
    - **xKey:** The data to use for the x-axis.
    - **yKey:** The data to use for the y-axis.

Putting these things together creates a basic chart.

#### Basic Example

```ts
// Angular entry point file
import '@angular/compiler';
import { bootstrapApplication } from '@angular/platform-browser';

import { AppComponent } from './app.component';

bootstrapApplication(AppComponent);
```

[Live example: Basic Example](https://www.ag-grid.com/charts/angular/create-a-basic-chart/examples/basic-example)

## Combination Charts

A chart can have more than one series, which can be useful when comparing datasets. To add another series to the chart, simply add another object to the series array, referencing the data to use.

```ts
this.chartOptions = {
    series: [
        { type: 'bar', xKey: 'month', yKey: 'iceCreamSales' } as AgBarSeriesOptions, // Existing 'Bar' Series, using 'iceCreamSales' data-points
        { type: 'line', xKey: 'month', yKey: 'avgTemp' } as AgLineSeriesOptions, // Additional 'Line' Series, using 'avgTemp' data-points
    ],
    // ...
};
```

Running the chart at this point will show the two series in the same chart.

#### Combination Charts Example

```ts
// Angular entry point file
import '@angular/compiler';
import { bootstrapApplication } from '@angular/platform-browser';

import { AppComponent } from './app.component';

bootstrapApplication(AppComponent);
```

[Live example: Combination Charts Example](https://www.ag-grid.com/charts/angular/create-a-basic-chart/examples/combination-charts-example)

### Configuring Secondary Axes

The chart above shows both series in a single chart, but given that the data-sets are quite different, it would make more sense to have a secondary axis for the second series.

To do this, first we need to link each series to the appropriate axis using the `yKeyAxis` property on the series:

```js
this.chartOptions = {
    series: [
        {
            type: 'bar',
            xKey: 'month',
            yKey: 'iceCreamSales',
            // y-axis Key, to link series to an axis
            yKeyAxis: 'priceAxis',
        },
        {
            type: 'line',
            xKey: 'month',
            yKey: 'avgTemp',
            // y-axis Key, to link series to an axis
            yKeyAxis: 'temperatureAxis',
        },
    ],
    // ...
};
```

The `yKeyAxis` property provides a way to reference a series from the axis configuration. To configure the axes, we need to add the `axes` property to the chart options, defining each axis and linking it to the appropriate series using the same keys defined in the `yKeyAxis` properties above:

```js
this.chartOptions = {
    axes: {
        // Use left axis for 'iceCreamSales' series
        priceAxis: {
            type: 'number',
            position: 'left',
        },
        // Use right axis for 'avgTemp' series
        temperatureAxis: {
            type: 'number',
            position: 'right',
        },
    },
    // ...
};
```

Let's breakdown what's happening here:

- **`axes.{key}`:** The key used to reference the axis, which should match the `yKeyAxis` property on the series.
- **`type`:** The type of axis to use - one of [Category](https://www.ag-grid.com/charts/angular/axes-types/#category), [Number](https://www.ag-grid.com/charts/angular/axes-types/#number), [Time](https://www.ag-grid.com/charts/angular/axes-types/#time) or [Log](https://www.ag-grid.com/charts/angular/axes-types/#log).
- **`position`:** The position on the chart where the axis should be rendered, e.g. 'top', 'bottom', 'right' or 'left'.

Now when we run our chart, we should see both series and three axes.

#### Second Series Example

```ts
// Angular entry point file
import '@angular/compiler';
import { bootstrapApplication } from '@angular/platform-browser';

import { AppComponent } from './app.component';

bootstrapApplication(AppComponent);
```

[Live example: Second Series Example](https://www.ag-grid.com/charts/angular/create-a-basic-chart/examples/second-series-example)

> **Note**
>
> Refer to our [Axes Configuration](https://www.ag-grid.com/charts/angular/axes-configuration/) docs for more information on configuring axes.

## Styling

Now we have a chart complete with multiple series and axes, the last thing to do is style the chart.

### Titles

Titles and subtitles can also be added to the chart via the `title` and `subtitle` properties.

```ts
this.chartOptions = {
    title: { text: 'Ice Cream Sales' },
    subtitle: { text: 'Data from 2022' },
    // ...
};
```

#### Titles Example

```ts
// Angular entry point file
import '@angular/compiler';
import { bootstrapApplication } from '@angular/platform-browser';

import { AppComponent } from './app.component';

bootstrapApplication(AppComponent);
```

[Live example: Titles Example](https://www.ag-grid.com/charts/angular/create-a-basic-chart/examples/title-example)

*Note: Refer to the [title](https://www.ag-grid.com/charts/options/#reference-AgChartOptions-title) and [subtitle](https://www.ag-grid.com/charts/options/#reference-AgChartOptions-subtitle) API docs for a full list of properties that can be configured*

### Legend

You may have noticed that the chart added a Legend when we added a second series to our chart. We can configure the Legend using the `legend` property, including adjusting its size and position.

```js
this.chartOptions = {
    legend: {
        position: 'right',
    },
    // ...
};
```

We should now see the Legend displayed on the right hand side of the chart, rather than underneath it.

#### Legend Example

```ts
// Angular entry point file
import '@angular/compiler';
import { bootstrapApplication } from '@angular/platform-browser';

import { AppComponent } from './app.component';

bootstrapApplication(AppComponent);
```

[Live example: Legend Example](https://www.ag-grid.com/charts/angular/create-a-basic-chart/examples/legend-example)

*Note: Refer to the [Legend](https://www.ag-grid.com/charts/angular/legend/) docs for more info*

### Renaming Series

As you can see, our Legend and Tooltips use the property name from the data directly. We can show something more human readable by adding the `yName` property to our series.

```js
this.chartOptions = {
    series: [
        { type: 'bar', xKey: 'month', yKey: 'iceCreamSales', yName: 'Ice Cream Sales' },
        // ...
    ],
    // ...
};
```

Now we should see our Legend and Tooltips using the `yName` value as opposed to the `yKey`.

#### Formatting Series Example

```ts
// Angular entry point file
import '@angular/compiler';
import { bootstrapApplication } from '@angular/platform-browser';

import { AppComponent } from './app.component';

bootstrapApplication(AppComponent);
```

[Live example: Formatting Series Example](https://www.ag-grid.com/charts/angular/create-a-basic-chart/examples/format-series-example)

### Formatting Axes

The last thing to do is format our axes labels to make the chart more readable. We can do this by using a `formatter` on the `label` property of the axis.

The `formatter` should be a function that receives the axis label data and returns a `String` to display. For example, we can format our right axis to include ' °C' with the following function:

```js
this.chartOptions = {
    axes: {
        // ...
        temperatureAxis: {
            type: 'number',
            position: 'right',
            label: {
                // Label value as a formatter function
                formatter: (params) => {
                    return params.value + ' °C';
                },
            },
        },
    },
    // ...
};
```

Now our chart should display formatted temperature values on the right axis.

#### Second Series Formatted Example

```ts
// Angular entry point file
import '@angular/compiler';
import { bootstrapApplication } from '@angular/platform-browser';

import { AppComponent } from './app.component';

bootstrapApplication(AppComponent);
```

[Live example: Second Series Formatted Example](https://www.ag-grid.com/charts/angular/create-a-basic-chart/examples/second-series-formatted-example)

*Note: Refer to the [axes](https://www.ag-grid.com/charts/options/#reference-AgChartOptions-axes) API docs for a full list of properties that can be configured*

## Test your Knowledge

1. Format the left axis using `toLocaleString()`

   *Hint: Add a formatter to the `axes.{key}.label` property*
2. Change the 'avgTemp' legend item label to 'Average Temperature (°C)'.

   *Hint: use the `yName` property on the 'avgTemp' series*

If you're stuck, check the source code of the example.

#### Complete Formatted Example

```ts
// Angular entry point file
import '@angular/compiler';
import { bootstrapApplication } from '@angular/platform-browser';

import { AppComponent } from './app.component';

bootstrapApplication(AppComponent);
```

[Live example: Complete Formatted Example](https://www.ag-grid.com/charts/angular/create-a-basic-chart/examples/complete-formatted-example)

## Summary

Congratulations, you've completed our introductory tutorial! By now, you should be familiar with a few key concepts of AG Charts:

- **Chart Options:** Object which contains all of the configuration options for the chart.
- **Data:** The data to be displayed within the chart.
- **Series:** Controls the chart type (series) and links it to the data. Multiple series can be used to create combination charts.
- **Axes:** Controls the Axes and links it to the data.
- **Styling & Formatting:** Controls the look and feel of the chart through formatters and series properties.
