Bar series are commonly used to show values for a discrete set of objects, such as item categories, specific items, or time periods such as years or quarters.
Because bar series are just transposed column series and have the same configuration, this section covers both series at once.
Column Series
Regular Columns
To create a column chart, we need to use series type 'column'. We also have to provide the xKey and yKey properties.
A minimal 'column' series config would therefore look like this:
In the snippet above we are using 'iphone' as the yKey, to show revenue per quarter for this product. Using this simple series config produces the following chart:
Stacked Columns
If the goal is to show the total quarterly revenue for each product category, multiple stacked series can be used
by adding more column-type series.
This example demonstrates stacked columns using the series configuration above. Additionally:
We set yName on each series to configure the display names to provide tooltip headers and legend entries.
Grouped Columns
If we want to show quarterly revenue for each product category as grouped columns, we can simply take the stacked column config from the example above and omit the stacked property.
This will produce the following chart:
Grouped Stacks
Stacks can be displayed in separate groups. The IDs of such groups should be specified in stackGroup property for each series (if left unset for some series, such series will be stacked together).
Grouped Stacks with a Shared Legend
Providing a matching legendItemName allows us to create multiple bar series that have synchronised legend items. When a legend item is clicked, all items that have a matching legendItemName will be toggled together.
Normalized Columns
Going back to our stacked column example, if we wanted to normalize the totals so that each column's segments add up to a certain value, for example 100, we could add the following to our series config:
normalizedTo:100
It's possible to use any non-zero value to normalize to.
Column Labels
It's possible to add labels to columns, by adding the following to the series config:
label:{}
That's it. The config can be empty like that. However, you might want to customise your labels. For example, by default the values are rounded to two decimal places for the labels, but in the example below even that is too much, so we use a label formatter that simply returns the integer part of the number:
label:{formatter:function(params){// if the data contains values that are not valid numbers,// the formatter's `value` will be `undefined`return params.value ===undefined?'': params.value.toFixed(0);}}
The above formatter produces an attractive chart where the labels don't stick out of their columns:
It's best to avoid using labels with grouped columns (or bars), because columns in grouped mode tend to be narrow and often won't fit a label.
To learn more about label configuration please refer to the API reference below.
Bar Series
'bar' series configuration is similar to the 'column' series configuration and all the same modes (stacked, grouped, normalized) apply to bars just as they do to columns.
To create a bar chart all you need to do is use type: 'bar' instead of type: 'column' in the series options.
With this simple change we go from stacked columns to stacked bars:
API Reference
Column Series
Properties available on the AgColumnSeriesOptions<DatumType = any> interface.
xKey *
Typestring
The key to use to retrieve x-values from the data.
yKey *
Typestring
The key to use to retrieve y-values from the data.
type
Type'column'
'column'
grouped
Typeboolean
Whether to group together (adjacently) separate columns.
stacked
Typeboolean
An option indicating if the columns should be stacked.
stackGroup
Typestring
An ID to be used to group stacked items.
normalizedTo
Typenumber
The number to normalise the column stacks to. Has no effect when grouped is true. For example, if normalizedTo is set to 100, the column stacks will all be scaled proportionally so that each of their totals is 100.
xName
Typestring
A human-readable description of the x-values. If supplied, this will be shown in the default tooltip and passed to the tooltip renderer as one of the parameters.
yName
Typestring
Human-readable description of the y-values. If supplied, a corresponding yName will be shown in the default tooltip and passed to the tooltip renderer as one of the parameters.
legendItemName
Typestring
Human-readable description of the y-values. If supplied, matching items with the same value will be toggled together.
fill
TypeCssColor
The colour to use for the fill of the columns.
stroke
TypeCssColor
The colours to use for the stroke of the columns.
strokeWidth
TypePixelSize
Default1
The width in pixels of the stroke for the columns.
fillOpacity
TypeOpacity
Default1
The opacity of the fill for the columns.
strokeOpacity
TypeOpacity
Default1
The opacity of the stroke for the columns.
lineDash
TypePixelSize[]
Defines how the column strokes 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.
lineDashOffset
TypePixelSize
The initial offset of the dashed line in pixels.
shadow
TypeAgDropShadowOptions
Configuration for the shadow used behind the chart series.
label
TypeAgColumnSeriesLabelOptions
Configuration for the labels shown on columns.
tooltip
TypeAgColumnSeriesTooltip
Series-specific tooltip configuration.
formatter
TypeFunction
Function used to return formatting for individual columns, based on the given parameters. If the current column is highlighted, the highlighted property will be set to true; make sure to check this if you want to differentiate between the highlighted and un-highlighted states.
listeners
TypeAgSeriesListeners<DatumType>
A map of event names to event listeners.
id
Typestring
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. Default: auto-generated value
data
TypeDatumType[]
The data to use when rendering the series. If this is not supplied, data must be set on the chart instead.
visible
Typeboolean
Whether or not to display the series.
showInLegend
Typeboolean
Whether or not to include the series in the legend.
cursor
Typestring
The cursor to use for hovered area markers. This config is identical to the CSS cursor property.
highlightStyle
TypeAgSeriesHighlightStyle
Configuration for series markers and series line highlighting when a marker / data point or a legend item is hovered over.
nodeClickRange
TypeAgChartInteractionRange
Range from a node a click triggers the listener.
Bar Series
Properties available on the AgBarSeriesOptions<DatumType = any> interface.
xKey *
Typestring
The key to use to retrieve x-values from the data.
yKey *
Typestring
The key to use to retrieve y-values from the data.
type
Type'bar'
'bar'
grouped
Typeboolean
Whether to group together (adjacently) separate bars.
stacked
Typeboolean
An option indicating if the bars should be stacked.
stackGroup
Typestring
An ID to be used to group stacked items.
normalizedTo
Typenumber
The number to normalise the bar stacks to. Has no effect when grouped is true. For example, if normalizedTo is set to 100, the bar stacks will all be scaled proportionally so that each of their totals is 100.
xName
Typestring
A human-readable description of the x-values. If supplied, this will be shown in the default tooltip and passed to the tooltip renderer as one of the parameters.
yName
Typestring
Human-readable description of the y-values. If supplied, a corresponding yName will be shown in the default tooltip and passed to the tooltip renderer as one of the parameters.
legendItemName
Typestring
Human-readable description of the y-values. If supplied, matching items with the same value will be toggled together.
fill
TypeCssColor
The colour to use for the fill of the bars.
stroke
TypeCssColor
The colours to use for the stroke of the bars.
strokeWidth
TypePixelSize
Default1
The width in pixels of the stroke for the bars.
fillOpacity
TypeOpacity
Default1
The opacity of the fill for the bars.
strokeOpacity
TypeOpacity
Default1
The opacity of the stroke for the bars.
lineDash
TypePixelSize[]
Defines how the bar strokes 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.
lineDashOffset
TypePixelSize
The initial offset of the dashed line in pixels.
shadow
TypeAgDropShadowOptions
Configuration for the shadow used behind the chart series.
label
TypeAgBarSeriesLabelOptions
Configuration for the labels shown on bars.
tooltip
TypeAgBarSeriesTooltip
Series-specific tooltip configuration.
formatter
TypeFunction
Function used to return formatting for individual bars, based on the given parameters. If the current bar is highlighted, the highlighted property will be set to true; make sure to check this if you want to differentiate between the highlighted and un-highlighted states.
listeners
TypeAgSeriesListeners<DatumType>
A map of event names to event listeners.
id
Typestring
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. Default: auto-generated value
data
TypeDatumType[]
The data to use when rendering the series. If this is not supplied, data must be set on the chart instead.
visible
Typeboolean
Whether or not to display the series.
showInLegend
Typeboolean
Whether or not to include the series in the legend.
cursor
Typestring
The cursor to use for hovered area markers. This config is identical to the CSS cursor property.
highlightStyle
TypeAgSeriesHighlightStyle
Configuration for series markers and series line highlighting when a marker / data point or a legend item is hovered over.