---
title: "Sparklines - Bar Customisation"
enterprise: true
framework: angular
version: "36.1.0"
---

# Sparklines - Bar Customisation

This section shows how Bar Sparklines can be customised by overriding the default bar options.

The following can be used to customise Bar Sparklines:

- [Bar Fill Options](https://www.ag-grid.com/angular-data-grid/sparklines-bar-customisation/#bar-fill-options)
- [Bar Stroke Options](https://www.ag-grid.com/angular-data-grid/sparklines-bar-customisation/#bar-stroke-options)
- [Bar Padding Options](https://www.ag-grid.com/angular-data-grid/sparklines-bar-customisation/#bar-padding-options)
- [Bar Label Options](https://www.ag-grid.com/angular-data-grid/sparklines-bar-customisation/#bar-label-options)
- [Axis Line Options](https://www.ag-grid.com/angular-data-grid/sparklines-bar-customisation/#axis-line-options)
- [Sparkline Padding Options](https://www.ag-grid.com/angular-data-grid/sparklines-bar-customisation/#sparkline-padding-options)

Also see [Additional Customisations](https://www.ag-grid.com/angular-data-grid/sparklines-bar-customisation/#additional-customisations) for more advanced customisations that are common across all sparklines.

The snippet below shows option overrides for the Bar Sparkline:

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    fill: '#5470c6',
    stroke: '#91cc75',
    highlight: {
        highlightedItem: {
            fill: '#fac858'
        }
    },
    min: 0,
    max: 1
},
```

In the snippet above, the `min` and `max` properties are optional.

`min` and `max` properties are used to specify the interval within which the data values lie. These boundaries are used to create a scale which will be used to map data values from `0px` to the size of the sparkline.

If the `min` and `max` properties are omitted, the domain will be set to the minimum and maximum values in the provided data, hence it could be different for different sparklines in the grid depending on the provided data.

The following example demonstrates the results of the Bar Sparkline options above:

#### Bar Sparkline Customisation

```ts
import { Component, ViewChild } from "@angular/core";
import { AgGridAngular } from "ag-grid-angular";
import {
  AgChartsCommunityModule,
  AgSparklineOptions,
} from "ag-charts-community";
import {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  enableDevValidations,
} from "ag-grid-community";
import {
  ClipboardModule,
  ContextMenuModule,
  SparklinesModule,
} from "ag-grid-enterprise";
import { getData } from "./data";
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  ClientSideRowModelModule,
  SparklinesModule.with(AgChartsCommunityModule),
  ClipboardModule,
  ContextMenuModule,
]);

@Component({
  selector: "my-app",
  standalone: true,
  imports: [AgGridAngular],
  template: `<ag-grid-angular
    style="width: 100%; height: 100%;"
    [columnDefs]="columnDefs"
    [defaultColDef]="defaultColDef"
    [rowData]="rowData"
    [rowHeight]="rowHeight"
  /> `,
})
export class AppComponent {
  columnDefs: ColDef[] = [
    { field: "symbol", maxWidth: 120 },
    { field: "name", minWidth: 250 },
    {
      field: "change",
      cellRenderer: "agSparklineCellRenderer",
      cellRendererParams: {
        sparklineOptions: {
          type: "bar",
          direction: "horizontal",
          min: 0,
          max: 1,
          fill: "#5470c6",
          stroke: "#91cc75",
          strokeWidth: 1,
          highlight: {
            highlightedItem: {
              fill: "#fac858",
            },
          },
        } as AgSparklineOptions,
      },
    },
    {
      field: "volume",
      maxWidth: 140,
    },
  ];
  defaultColDef: ColDef = {
    flex: 1,
    minWidth: 100,
  };
  rowData: any[] | null = getData();
  rowHeight = 50;
}
```

[Live example: Bar Sparkline Customisation](https://www.ag-grid.com/examples/sparklines-bar-customisation/bar-sparkline-customisation/angular)

Note that `min` and `max` properties have been set to `0` and `1` respectively, indicating that the supplied data across all sparklines will contain values from `0` to `1`. This allows easy comparisons across the different sparklines in the grid column as all sparklines will have the same domain.

## Bar Fill Options

To apply a custom color to the bars, set the `fill` property in `sparklineOptions` as shown:

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    fill: '#91cc75', // sets the bar fill
}
```

![Bar fill default](https://www.ag-grid.com/_astro/default.DJ2gnqOE.png)

Default

![Bar fill customisation](https://www.ag-grid.com/_astro/custom-fill.BgD2sZSW.png)

Custom fill

It is possible to set the fill for the highlighted state of the bar by adding `fill` in `highlight` options as follows:

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    highlight: {
        highlightedItem: {
            fill: 'orange', // sets the highlighted bar fill
        }
    }
}
```

![Highlighted Bar fill default](https://www.ag-grid.com/_astro/default-highlighted.Qp0K2JPt.png)

Default highlighted fill

![Highlighted Bar fill customisation](https://www.ag-grid.com/_astro/custom-highlighted-fill.B23jC8_A.png)

Custom highlighted fill

The given `fill` string can be in one of the following formats:

- `#rgb` - Short Hex Code
- `#rrggbb` - Hex Code
- `rgb(r, g, b)` - RGB
- `rgba(r, g, b, a)` - RGB with an alpha channel
- CSS color keyword - such as `aqua`, `orange`, etc.

## Bar Stroke Options

By default, the `strokeWidth` of each bar is `0`, so no outline is visible around the bars.

To add a stroke, modify the `strokeWidth` and `stroke` properties as shown below.

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    stroke: '#ec7c7d', // sets the bar stroke
    strokeWidth: 2, // sets the bar stroke width
    highlight: {
        highlightedItem: {
            stroke: '#b5ec7c', // sets the highlighted bar stroke
            strokeWidth: 2, // sets the highlighted bar stroke width
        }
    }
}
```

- In the snippet above, we have configured the bar stroke to be `2`px in the un-highlighted state, and `2`px in the highlighted state.
- Note that the `stroke` property is also different depending on the highlighted state of the bar.

Here is the result of the configuration shown in the above snippet.

![Stroke default](https://www.ag-grid.com/_astro/default.DJ2gnqOE.png)

Default

![Stroke customisation](https://www.ag-grid.com/_astro/custom-stroke.BAZegRy5.png)

Custom stroke

![Stroke customisation for highlighted state](https://www.ag-grid.com/_astro/custom-highlighted-stroke.DpNjQIfh.png)

Custom highlighted stroke

> **Note**
>
> If `strokeWidth` is set to a value greater than `1`, it is recommended to set the axis line `strokeWidth` to the same value in order to preserve the alignment of the bars with the axis line.

See AG Charts [Series Markers](https://www.ag-grid.com/charts/javascript/markers/) for more information on marker options. See AG Charts [Stylers](https://www.ag-grid.com/charts/javascript/stylers/) for more information on item stylers.

## Bar Padding Options

The spacing between bars is adjustable via the `paddingInner` property. This property takes values between 0 and 1 and is available for axis `type: 'category'` only.

It is a proportion of the “step”, which is the interval between the start of a band and the start of the next band.

Here's an example.

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    axis: {
        type: 'category',
        paddingInner: 0.5, // sets the padding between bars.
    }
}
```

![Bar padding default](https://www.ag-grid.com/_astro/default.DJ2gnqOE.png)

Default

![PaddingInner customisation](https://www.ag-grid.com/_astro/custom-padding-inner.DOeBnCEi.png)

Custom paddingInner

The padding on the outer edges of the first and last bars can also be adjusted. As with `paddingInner`, this value can be between 0 and 1 and is available for axis `type: 'category'` only.

If the value of `paddingOuter` is increased, the axis line will stick out more at both ends of the sparkline.

Here's a snippet where the `paddingOuter` is set to `0`.

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    axis: {
        type: 'category',
        paddingOuter: 0, // sets the padding on the outer edge of the first and last bars.
    }
}
```

In this case there will be no gap on either end of the sparkline, i.e. between the axis line start and the first bar and the axis line end and the last bar. This is demonstrated below in the middle sparkline.

![bar padding default](https://www.ag-grid.com/_astro/default.DJ2gnqOE.png)

Default

![PaddingOuter customisation](https://www.ag-grid.com/_astro/custom-padding-outer.DvoN4Ngr.png)

No paddingOuter

![PaddingOuter customisation](https://www.ag-grid.com/_astro/custom-padding-outer-2.DOdf7tzb.png)

Increased paddingOuter

## Bar Label Options

To enable bar labels, set the `enabled` property in `label` options as shown:

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    label: {
        enabled: true // show bar labels
    }
}
```

![Bar default](https://www.ag-grid.com/_astro/default.DJ2gnqOE.png)

Default

![Bar labels enabled](https://www.ag-grid.com/_astro/default-label.DOTo4wyS.png)

Label enabled

It is possible to change the text value displayed as the label of individual bars by adding a `formatter` callback function to `label` options as follows:

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    label: {
        enabled: true,
        formatter: labelFormatter
    }
}

function labelFormatter({ value }) {
    return `${value}%`
}
```

![Bar default](https://www.ag-grid.com/_astro/default.DJ2gnqOE.png)

Default

![Bar label text customisation](https://www.ag-grid.com/_astro/custom-label-formatter.C7I_RcbI.png)

Custom label text

To customise the label text style, set the style attributes in `label` options as follows:

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    label: {
        enabled: true,
        fontWeight: 'bold',
        fontStyle: 'italic',
        fontSize: 9,
        fontFamily: 'Arial, Helvetica, sans-serif',
        color: 'black',
    }
}
```

![Bar default](https://www.ag-grid.com/_astro/default.DJ2gnqOE.png)

Default

![Bar label text style customisation](https://www.ag-grid.com/_astro/custom-label-styles.CecC1G0P.png)

Custom label text styles

The position of the labels can be specified by setting the `placement` property in `label` options. By default, the labels are positioned at the end of the bars on the inside, i.e. `placement` is set to `insideEnd `. The snippet below shows how the positioning of the label can be modified:

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    label: {
        enabled: true,
        placement: 'inside-center', // positions the labels in the center of the bars
    }
}
```

Label `placement` options include `inside-center`, `inside-start`, `inside-end`, `outside-start` or `outside-end` from the [AG Charts Label Placement](https://www.ag-grid.com/charts/javascript/bar-series/#reference-AgBarSeriesOptions-label-placement) documentation. These are shown in the screenshots below.

![Bar label inside-start placement](https://www.ag-grid.com/_astro/custom-label-placement-inside-start.C8ZFn2tF.png)

inside-start

![Bar label inside-center placement](https://www.ag-grid.com/_astro/custom-label-placement-inside-center.C1FahQw6.png)

inside-center

![Bar label inside-end placement](https://www.ag-grid.com/_astro/custom-label-placement-inside-end.C7QDul4g.png)

inside-end

![Bar label outside-end placement](https://www.ag-grid.com/_astro/custom-label-placement-outside-end.CYWC2qsB.png)

outside-end

> **Note**
>
> When configuring labels with placement: `outside-end` or `outside-start`, it is recommended to add some padding to the sparkline using the `padding` options in order to prevent the labels from being clipped.

## Axis Line Options

By default, an axis line is displayed which can be modified using the `axis` options.

Here is a snippet to demonstrate axis formatting.

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    axis: {
        stroke: '#7cecb3', // sets the axis line stroke
        strokeWidth: 3, // sets the axis line strokeWidth
    },
}
```

![Axis line default](https://www.ag-grid.com/_astro/default.DJ2gnqOE.png)

Default axis line

![Axis line customisation](https://www.ag-grid.com/_astro/custom-axis.CYtWS7KE.png)

Custom axis line

> **Note**
>
> It's possible to remove the axis line entirely by setting the axis `strokeWidth` to `0`.

## Sparkline Padding Options

To add extra space around the sparklines, custom `padding` options can be applied in the following way.

```js
sparklineOptions: {
    type: 'bar',
    direction: 'horizontal',
    // sets the padding around the sparklines
    padding: {
        top: 10,
        right: 5,
        bottom: 10,
        left: 5
    },
}
```

- The `top`, `right`, `bottom` and `left` properties are all optional and can be modified independently.

![Padding customisation](https://www.ag-grid.com/_astro/default-padding.TuUP4xV4.png)

Default padding

![Padding customisation](https://www.ag-grid.com/_astro/custom-padding.B0PSyuJP.png)

Custom padding

## Building Progress Bars

A progress bar can be used to visualise and compare values across multiple sparklines in the grid. It can illustrate values which have a fixed domain such as percentages and scores.

The following example shows how to build progress bars using bar sparklines. Note that:

- In order to display a progress bar in a sparkline, the data array should only contain a single value, more values in the data array will produce additional bars in the same sparkline.
- `min` and `max` properties have been set to `0` and `100`, indicating that the supplied data across all sparklines will contain values from `0` to `100`.
- This allows easy comparisons of percentages across the different sparklines in the grid column as all sparklines will have the same domain.
- The `itemStyler` callback function is used to dynamically set the fill color of each progress bar to different color values based on the data `yValue` .
- Percentage Y values are displayed on the inside end of each bar by configuring `label` options.
- The axis line and padding are removed to allow more space in each cell for the progress bar.

#### Bar Sparkline – Progress Bars

```ts
import { Component, ViewChild } from "@angular/core";
import { AgGridAngular } from "ag-grid-angular";
import {
  AgBarSeriesItemStylerParams,
  AgBarSeriesStyle,
  AgChartLabelFormatterParams,
  AgChartsCommunityModule,
  AgSparklineOptions,
} from "ag-charts-community";
import {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  enableDevValidations,
} from "ag-grid-community";
import {
  ClipboardModule,
  ContextMenuModule,
  SparklinesModule,
} from "ag-grid-enterprise";
import { getData } from "./data";
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  ClientSideRowModelModule,
  SparklinesModule.with(AgChartsCommunityModule),
  ClipboardModule,
  ContextMenuModule,
]);

@Component({
  selector: "my-app",
  standalone: true,
  imports: [AgGridAngular],
  template: `<ag-grid-angular
    style="width: 100%; height: 100%;"
    [columnDefs]="columnDefs"
    [defaultColDef]="defaultColDef"
    [rowData]="rowData"
    [rowHeight]="rowHeight"
  /> `,
})
export class AppComponent {
  columnDefs: ColDef[] = [
    { field: "symbol", maxWidth: 120 },
    { field: "name", minWidth: 250 },
    {
      field: "change",
      cellRenderer: "agSparklineCellRenderer",
      cellRendererParams: {
        sparklineOptions: {
          type: "bar",
          direction: "horizontal",
          label: {
            enabled: true,
            color: "white",
            fontSize: 10,
            fontWeight: "bold",
            formatter: (params: AgChartLabelFormatterParams) => {
              return `${params.value}%`;
            },
          },
          min: 0,
          max: 100,
          tooltip: {
            enabled: false,
          },
          itemStyler: itemStyler,
        } as AgSparklineOptions,
      },
    },
    {
      field: "volume",
      maxWidth: 140,
    },
  ];
  defaultColDef: ColDef = {
    flex: 1,
    minWidth: 100,
  };
  rowData: any[] | null = getData();
  rowHeight = 50;
}

function itemStyler(
  params: AgBarSeriesItemStylerParams<any>,
): AgBarSeriesStyle {
  const { yValue } = params;
  return {
    fill: yValue <= 20 ? "#4fa2d9" : yValue < 60 ? "#277cb5" : "#195176",
  };
}
```

[Live example: Bar Sparkline – Progress Bars](https://www.ag-grid.com/examples/sparklines-bar-customisation/bar-sparkline-progress-bars/angular)

## Additional Customisations

More advanced customisations are discussed separately in the following sections:

- [Axis](https://www.ag-grid.com/angular-data-grid/sparklines-axis-types/) - configure the axis type via `axis` options.
- [Tooltips](https://www.ag-grid.com/angular-data-grid/sparklines-tooltips/) - configure tooltips using `tooltip` options.
- [Points of Interest](https://www.ag-grid.com/angular-data-grid/sparklines-points-of-interest/) - configure individual points of interest using an `itemStyler`.
