A Pyramid Series is a triangular shaped visualisation that uses the height of each segment to represent its value as a proportion of the whole.
Simple Pyramid Copy Link
import {
AgChartOptions,
AgCharts,
AnimationModule,
ContextMenuModule,
LegendModule,
ModuleRegistry,
PyramidSeriesModule,
} from "ag-charts-enterprise";
import { getData } from "./data";
ModuleRegistry.registerModules([
AnimationModule,
LegendModule,
PyramidSeriesModule,
ContextMenuModule,
]);
const options: AgChartOptions = {
data: getData(),
title: {
text: "Revenue Open by Sales Stage",
},
series: [
{
type: "pyramid",
stageKey: "group",
valueKey: "value",
},
],
};
options.container = document.getElementById("myChart");
const chart = AgCharts.create(options);
export function getData() {
return [
{ group: "Qualify", value: 7910 },
{ group: "Develop", value: 8170 },
{ group: "Propose", value: 7260 },
{ group: "Close", value: 4460 },
];
}
To create a Pyramid Series, use the pyramid series type.
{
series: [
{
type: 'pyramid',
stageKey: 'group',
valueKey: 'value',
},
],
}In this configuration:
stageKeydefines the categories, each of which is mapped to segments in the pyramid.valueKeyprovides the numerical values, determining the height of each segment.
Horizontal Pyramid Copy Link
import {
AgChartOptions,
AgCharts,
AnimationModule,
ContextMenuModule,
ModuleRegistry,
PyramidSeriesModule,
} from "ag-charts-enterprise";
import { getData } from "./data";
ModuleRegistry.registerModules([
AnimationModule,
PyramidSeriesModule,
ContextMenuModule,
]);
const options: AgChartOptions = {
data: getData(),
title: {
text: "Revenue Open by Sales Stage",
},
seriesArea: {
padding: {
left: 20,
right: 20,
},
},
series: [
{
type: "pyramid",
stageKey: "group",
valueKey: "value",
direction: "horizontal",
},
],
};
options.container = document.getElementById("myChart");
const chart = AgCharts.create(options);
export function getData() {
return [
{ group: "Qualify", value: 7910 },
{ group: "Develop", value: 8170 },
{ group: "Propose", value: 7260 },
{ group: "Close", value: 4460 },
];
}
To create a horizontal Pyramid Series, set the direction to horizontal.
{
direction: 'horizontal',
} Reverse Pyramid Copy Link
import {
AgChartOptions,
AgCharts,
AnimationModule,
ContextMenuModule,
LegendModule,
ModuleRegistry,
PyramidSeriesModule,
} from "ag-charts-enterprise";
import { getData } from "./data";
ModuleRegistry.registerModules([
AnimationModule,
LegendModule,
PyramidSeriesModule,
ContextMenuModule,
]);
const options: AgChartOptions = {
data: getData(),
title: {
text: "Revenue Open by Sales Stage",
},
seriesArea: {
padding: {
left: 20,
right: 20,
},
},
series: [
{
type: "pyramid",
stageKey: "group",
valueKey: "value",
reverse: true,
},
],
};
options.container = document.getElementById("myChart");
const chart = AgCharts.create(options);
export function getData() {
return [
{ group: "Qualify", value: 7910 },
{ group: "Develop", value: 8170 },
{ group: "Propose", value: 7260 },
{ group: "Close", value: 4460 },
];
}
To reverse a Pyramid Series, set reverse to true.
{
reverse: true,
} Customisation Copy Link
Fills Copy Link
import {
AgChartOptions,
AgCharts,
AnimationModule,
ContextMenuModule,
LegendModule,
ModuleRegistry,
PyramidSeriesModule,
} from "ag-charts-enterprise";
import { getData } from "./data";
ModuleRegistry.registerModules([
AnimationModule,
LegendModule,
PyramidSeriesModule,
ContextMenuModule,
]);
const options: AgChartOptions = {
data: getData(),
title: {
text: "Revenue Open by Sales Stage",
},
seriesArea: {
padding: {
left: 20,
right: 20,
},
},
series: [
{
type: "pyramid",
stageKey: "group",
valueKey: "value",
fills: ["#5C6BC0", "#3F51B5", "#303F9F", "#1A237E"],
},
],
};
options.container = document.getElementById("myChart");
const chart = AgCharts.create(options);
export function getData() {
return [
{ group: "Qualify", value: 7910 },
{ group: "Develop", value: 8170 },
{ group: "Propose", value: 7260 },
{ group: "Close", value: 4460 },
];
}
The colours in a Pyramid Series can be customised with the fills property.
{
fills: ['#5C6BC0', '#3F51B5', '#303F9F', '#1A237E'],
} Shape Copy Link
import {
AgCharts,
AgPyramidSeriesOptions,
AgStandaloneChartOptions,
AnimationModule,
ContextMenuModule,
LegendModule,
ModuleRegistry,
PyramidSeriesModule,
} from "ag-charts-enterprise";
import { getData } from "./data";
const ASPECT_RATIOS: Record<string, number> = {
"2-3": 2 / 3,
equilateral: 1.1547,
"3-2": 3 / 2,
};
ModuleRegistry.registerModules([
AnimationModule,
LegendModule,
PyramidSeriesModule,
ContextMenuModule,
]);
const options: AgStandaloneChartOptions = {
data: getData(),
title: {
text: "Revenue Open by Sales Stage",
},
seriesArea: {
padding: {
left: 20,
right: 20,
},
},
series: [
{
type: "pyramid",
stageKey: "group",
valueKey: "value",
aspectRatio: 3 / 2,
label: {
enabled: false,
},
},
],
};
options.container = document.getElementById("myChart");
const chart = AgCharts.create(options);
function directionChange(event: Event) {
const direction = (event.target as HTMLInputElement).value as
| "horizontal"
| "vertical";
(options.series![0] as AgPyramidSeriesOptions).direction = direction;
chart.update(options);
}
function aspectRatioChange(event: Event) {
const aspectRatio = ASPECT_RATIOS[(event.target as HTMLInputElement).value];
(options.series![0] as AgPyramidSeriesOptions).aspectRatio = aspectRatio;
chart.update(options);
}
if (typeof window !== "undefined") {
// Attach external event handlers to window so they can be called from index.html
(<any>window).directionChange = directionChange;
(<any>window).aspectRatioChange = aspectRatioChange;
}
export function getData() {
return [
{ group: "Qualify", value: 7910 },
{ group: "Develop", value: 8170 },
{ group: "Propose", value: 7260 },
{ group: "Close", value: 4460 },
];
}
The shape of the triangle can be set using the aspectRatio property.
{
aspectRatio: 3 / 2,
}In this configuration:
aspectRatiois set such that width will grow3pxfor every2pxof height.
Labels Copy Link
The values can be displayed inside or outside each segment using the label option, and the segment name can be shown with the stageLabel option.
import {
AgCharts,
AgFunnelSeriesLabelPlacement,
AgPyramidSeriesOptions,
AgStandaloneChartOptions,
AnimationModule,
ContextMenuModule,
LegendModule,
ModuleRegistry,
PyramidSeriesModule,
} from "ag-charts-enterprise";
import { DataType, getData } from "./data";
const initialPlacement: AgFunnelSeriesLabelPlacement = "inside-center";
ModuleRegistry.registerModules([
AnimationModule,
LegendModule,
PyramidSeriesModule,
ContextMenuModule,
]);
const options: AgStandaloneChartOptions<DataType> = {
data: getData(),
title: {
text: "Revenue Open by Sales Stage",
},
subtitle: {
text: initialPlacement,
},
animation: {
enabled: false,
},
seriesArea: {
padding: {
left: 20,
right: 20,
},
},
series: [
{
type: "pyramid",
stageKey: "group",
valueKey: "value",
direction: "vertical",
label: {
enabled: true,
placement: initialPlacement,
},
stageLabel: {
placement: "before",
spacing: 40,
},
},
],
};
options.container = document.getElementById("myChart");
const chart = AgCharts.create(options);
function setPlacement(value: string) {
(options.series![0] as AgPyramidSeriesOptions<DataType>).label!.placement =
value as AgFunnelSeriesLabelPlacement;
options.subtitle!.text = value;
chart.update(options);
}
function setDirection(event: Event) {
const direction = (event.target as HTMLInputElement).value as
| "vertical"
| "horizontal";
options.series = [
{ ...(options.series![0] as AgPyramidSeriesOptions<DataType>), direction },
];
chart.update(options);
}
function setStageLabelPlacement(event: Event) {
const placement = (event.target as HTMLInputElement).value as
| "before"
| "after";
const series = options.series![0] as AgPyramidSeriesOptions<DataType>;
options.series = [
{ ...series, stageLabel: { ...series.stageLabel, placement } },
];
chart.update(options);
}
if (typeof window !== "undefined") {
// Attach external event handlers to window so they can be called from index.html
(<any>window).setPlacement = setPlacement;
(<any>window).setDirection = setDirection;
(<any>window).setStageLabelPlacement = setStageLabelPlacement;
}
export interface DataType {
group: string;
value: number;
}
export function getData(): DataType[] {
return [
{ group: "Qualify", value: 7910 },
{ group: "Develop", value: 8170 },
{ group: "Propose", value: 7260 },
{ group: "Close", value: 4460 },
];
}
{
label: {
enabled: true,
placement: 'inside-center',
},
stageLabel: {
placement: 'before',
},
}In this configuration:
- The label is positioned as
inside-center. Use the dropdown to see all available placements.startandendare above and below the segment when vertical, left and right of it when horizontal.beforeandafterare the other two sides, matchingstageLabel.placement.
stageLabel.placementpositions the segment names on either side of the chart.- On a vertical pyramid,
beforeandafterare mirrored when RTL Layout is enabled. - Providing
placementas an ordered array (e.g.['inside-center', 'outside-end']) lets a label that does not fit inside its segment fall back to an outside position.
See Series Labels for the full set of label placement and collision avoidance options, and the API Reference for additional customisation options.
Pyramid Chart Examples Copy Link
See more Pyramid Chart examples in the AG Charts Gallery.
API Reference Copy Link
Properties available on the AgPyramidSeriesOptions interface.
- type required
'pyramid' - Configuration for the Pyramid Series.
- stageKey required
DatumKey - The key to use to retrieve stage values from the data.
- valueKey required
DatumKey - The key to use to retrieve values from the data.
- id
stringdefault: auto-generated value - Primary identifier for the series. This is provided as `seriesId` in user callbacks to differentiate multiple series. Auto-generated ids are subject to future change without warning, if your callbacks need to vary behaviour by series please supply your own unique `id` value.
- context
ContextDefault - Context object to use in callbacks.
- data
DatumDefault[] - The data to use when rendering the series. If this is not supplied, data must be set on the chart instead.
- visible
boolean - Whether to display the series.
- cursor
string - The cursor to use for hovered markers. This config is identical to the CSS `cursor` property.
- highlight
AgHighlightOptions - Configuration for highlighting when a series or legend item is hovered over.
- nodeClickRange
InteractionRange - Range from a node that a click triggers the listener.
- showInLegend
boolean - Whether to include the series in the legend.
- listeners
AgSeriesListeners - A map of event names to event listeners.
- fills
AgColorType[] - The colours to cycle through for the fills of the stages. An array of colour strings, or fill objects for gradients, patterns, or images.
- strokes
CssColor[] - The colours to cycle through for the strokes of the stages.
- fillOpacity
Opacity - The opacity of the fill for the stages.
- strokeOpacity
Opacity - The opacity of the stroke for the stages.
- strokeWidth
PixelSize - The width in pixels of the stroke for the stages.
- direction
'horizontal' | 'vertical' - Stage rendering direction.
- reverse
boolean - Reverse the order of the stages.
- spacing
number - Spacing between the stages.
- aspectRatio
number - Ratio of the triangle width to its height. When unset, the triangle will fill the available space.
- label
AgPyramidSeriesLabelOptions - Configuration for the labels shown on stages.
- stageLabel
AgPyramidSeriesStageLabelOptions - Configuration for the stage labels.
- shadow
AgDropShadowOptions - Configuration for the shadow used behind the series items.
- tooltip
AgSeriesTooltip - Series-specific tooltip configuration.
- itemStyler
Styler - Function used to return formatting for individual bars, based on the given parameters.
- lineDash
PixelSize[] - An array specifying the length in pixels of alternating dashes and gaps.
- lineDashOffset
PixelSize - The initial offset of the dashed line in pixels.
Properties available on the AgPyramidSeriesOptions interface.
- type required
'pyramid' - Configuration for the Pyramid Series.
- stageKey required
DatumKey - The key to use to retrieve stage values from the data.
- valueKey required
DatumKey - The key to use to retrieve values from the data.
- id
stringdefault: auto-generated value - Primary identifier for the series. This is provided as `seriesId` in user callbacks to differentiate multiple series. Auto-generated ids are subject to future change without warning, if your callbacks need to vary behaviour by series please supply your own unique `id` value.
- context
ContextDefault - Context object to use in callbacks.
- data
DatumDefault[] - The data to use when rendering the series. If this is not supplied, data must be set on the chart instead.
- visible
boolean - Whether to display the series.
- cursor
string - The cursor to use for hovered markers. This config is identical to the CSS `cursor` property.
- highlight
AgHighlightOptions - Configuration for highlighting when a series or legend item is hovered over.
- nodeClickRange
InteractionRange - Range from a node that a click triggers the listener.
- showInLegend
boolean - Whether to include the series in the legend.
- listeners
AgSeriesListeners - A map of event names to event listeners.
- fills
AgColorType[] - The colours to cycle through for the fills of the stages. An array of colour strings, or fill objects for gradients, patterns, or images.
- strokes
CssColor[] - The colours to cycle through for the strokes of the stages.
- fillOpacity
Opacity - The opacity of the fill for the stages.
- strokeOpacity
Opacity - The opacity of the stroke for the stages.
- strokeWidth
PixelSize - The width in pixels of the stroke for the stages.
- direction
'horizontal' | 'vertical' - Stage rendering direction.
- reverse
boolean - Reverse the order of the stages.
- spacing
number - Spacing between the stages.
- aspectRatio
number - Ratio of the triangle width to its height. When unset, the triangle will fill the available space.
- label
AgPyramidSeriesLabelOptions - Configuration for the labels shown on stages.
- stageLabel
AgPyramidSeriesStageLabelOptions - Configuration for the stage labels.
- shadow
AgDropShadowOptions - Configuration for the shadow used behind the series items.
- tooltip
AgSeriesTooltip - Series-specific tooltip configuration.
- itemStyler
Styler - Function used to return formatting for individual bars, based on the given parameters.
- lineDash
PixelSize[] - An array specifying the length in pixels of alternating dashes and gaps.
- lineDashOffset
PixelSize - The initial offset of the dashed line in pixels.