---
title: "Axis Grid Lines & Band Shading"
framework: javascript
version: "14.1.0"
---

# Axis Grid Lines & Band Shading

Grid lines are horizontal and vertical lines that divide a chart into sections, providing a visual reference for interpreting data.

## Enabling Grid Lines

Grid lines are shown by default on `number`, `log` and `time` axes types, and are disabled by default on `category` axes.

To change this, use the `gridLine.enabled` property on each axis.

## Customising Grid Lines

Grid lines can be styled via the `gridLine.style` property on each axis.

#### Axis Grid Lines

```ts
import {
  AgCartesianChartOptions,
  AgCharts,
  CategoryAxisModule,
  LegendModule,
  LineSeriesModule,
  ModuleRegistry,
  NumberAxisModule,
} from "ag-charts-community";

ModuleRegistry.registerModules([
  CategoryAxisModule,
  LegendModule,
  LineSeriesModule,
  NumberAxisModule,
]);

const options: AgCartesianChartOptions = {
  title: {
    text: "Most Common Girls' First Names In English",
  },
  subtitle: {
    text: "over the past 100 years",
  },
  data: [
    { name: "Mary", count: 234000 },
    { name: "Patricia", count: 211000 },
    { name: "Jennifer", count: 178000 },
    { name: "Elizabeth", count: 153000 },
    { name: "Linda", count: 123000 },
  ],
  series: [
    {
      type: "line",
      xKey: "name",
      yKey: "count",
    },
  ],
  axes: {
    x: {
      type: "category",
      gridLine: {
        enabled: true,
      },
    },
    y: {
      type: "number",
      gridLine: {
        enabled: true,
      },
    },
  },
};

options.container = document.getElementById("myChart");

const chart = AgCharts.create(options);

function setGridStyle1() {
  var gridStyle = [
    {
      stroke: "gray",
      lineDash: [10, 5],
    },
    {
      stroke: "lightgray",
      lineDash: [5, 5],
    },
  ];
  options.axes!.x!.gridLine!.style = gridStyle;
  options.axes!.y!.gridLine!.style = gridStyle;

  chart.update(options);
}

function setGridStyle2() {
  var xGridStyle = [
    {
      stroke: "red",
      lineDash: [3, 3],
    },
  ];
  var yGridStyle = [
    {
      stroke: "green",
      lineDash: [8, 3, 3, 3],
    },
  ];
  options.axes!.x!.gridLine!.style = xGridStyle;
  options.axes!.y!.gridLine!.style = yGridStyle;

  chart.update(options);
}

function setDefaultGridStyle() {
  delete options.axes!.x!.gridLine!.style;
  delete options.axes!.y!.gridLine!.style;

  chart.update(options);
}

if (typeof window !== "undefined") {
  // Attach external event handlers to window so they can be called from index.html
  (<any>window).setGridStyle1 = setGridStyle1;
  (<any>window).setGridStyle2 = setGridStyle2;
  (<any>window).setDefaultGridStyle = setDefaultGridStyle;
}
```

[Live example: Axis Grid Lines](https://www.ag-grid.com/charts/typescript/axes-grid-lines/examples/axis-grid-lines)

```js
{
    gridLine: {
        style: [
            {
                stroke: 'gray',
                lineDash: [10, 5],
            },
            {
                stroke: 'lightgray',
                lineDash: [5, 5],
            },
        ],
    },
}
```

The `gridLine.style` property takes an array of objects containing styling properties:

- `stroke` - The colour of the line.
- `strokeWidth` - The width of the line. This overrides the top level `gridLine.width` option.
- `lineDash` - How the line stroke is rendered. Every number in the array specifies the length in pixels of alternating dashes and gaps. If the array is empty, the grid lines will be solid without any dashes.
- `fill` - The colour of the fill between grid lines.
- `fillOpacity` - The opacity of the fill between grid lines.

Each object in the `gridLine.style` array is applied to the each grid line sequentially, looping around if necessary. This allows alternating styles across multiple grid lines, or styling each individual grid line separately.

## Alternating Band Shading

Alternating band shading can be achieved using the `fill` and `fillOpacity` properties of the objects in the `gridLine.style` array.

#### Axis Grid Fills

```ts
import {
  AgCartesianChartOptions,
  AgCharts,
  CategoryAxisModule,
  LegendModule,
  LineSeriesModule,
  ModuleRegistry,
  NumberAxisModule,
} from "ag-charts-community";

ModuleRegistry.registerModules([
  CategoryAxisModule,
  LegendModule,
  LineSeriesModule,
  NumberAxisModule,
]);

const options: AgCartesianChartOptions = {
  title: {
    text: "Most Common Girls' First Names In English",
  },
  subtitle: {
    text: "over the past 100 years",
  },
  data: [
    { name: "Mary", count: 234000 },
    { name: "Patricia", count: 211000 },
    { name: "Jennifer", count: 178000 },
    { name: "Elizabeth", count: 153000 },
    { name: "Linda", count: 123000 },
  ],
  series: [
    {
      type: "line",
      xKey: "name",
      yKey: "count",
    },
  ],
  axes: {
    x: {
      type: "category",
      gridLine: {
        style: [
          {
            fill: "#999",
            fillOpacity: 0.1,
            strokeWidth: 0,
          },
          {},
        ],
      },
    },
  },
};

options.container = document.getElementById("myChart");

const chart = AgCharts.create(options);
```

[Live example: Axis Grid Fills](https://www.ag-grid.com/charts/typescript/axes-grid-lines/examples/axis-grid-fills)

```js
{
    gridLine: {
        style: [
            {
                fill: '#999',
                fillOpacity: 0.1,
                strokeWidth: 0, //don't show lines around the bands
            },
            {}, //empty object for an unshaded band
        ],
    },
}
```

> **Note**
>
> The interval and position of grid lines is controlled by the [Axis Interval](https://www.ag-grid.com/charts/javascript/axes-intervals/) options.

## API Reference

#### GridLine Options

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| enabled | boolean |  | Set to `false` to hide the axis grid lines. |
| width | PixelSize |  | The width in pixels of the axis grid lines. |
| style | AgAxisGridStyle[] |  | Configuration of the lines used to form the grid in the chart series area. |
| style.fill | CssColor |  | The colour of the fill between grid lines. |
| style.fillOpacity | Ratio |  | The opacity of the fill between grid lines. |
| style.stroke | CssColor |  | The colour of the grid line. |
| style.strokeWidth | PixelSize |  | The width of the grid line in pixels. |
| style.lineDash | PixelSize[] |  | Defines how the grid lines are rendered. Every number in the array specifies the length in pixels of alternating dashes and gaps. For example, `[6, 3]` means dashes with a length of `6` pixels with gaps between of `3` pixels. |
