A combination chart combines two or more series types allowing for flexible data visualisations. They are ideal for making visual comparisons of different sets of data in a single chart.
Combination Series Types Copy Link
Series types can be combined with other series sharing the same axis type.
- Cartesian:
bar,line,area,scatter,bubble,histogram,range-bar,range-area,box-plot,candlestick,hlcandohlc. - Polar:
radar-line,radar-area,radial-columnandnightingale. pieanddonut.
The type property must be specified explicitly on each individual series object in the series options array, as shown below:
{
series: [
{
type: 'bar', // use 'bar' series
xKey: 'year',
yKey: 'men',
// ...other series options
},
{
type: 'line', // use 'line' series
xKey: 'year',
yKey: 'portions',
// ...other series options
},
],
}The snippet above shows the configuration required for a combination chart consisting of a bar and line series.
The example below demonstrates two common combination chart types. You can switch between these two combination chart types using the buttons above the chart. Please note:
- Series are rendered according to the order in which they are added in the
seriesarray. - The area and line series are plotted on a Secondary Axis with a different scale.
import {
AgBarSeriesOptions,
AgCartesianChartOptions,
AgCartesianSeriesOptions,
AgCharts,
AgLineSeriesOptions,
AreaSeriesModule,
BarSeriesModule,
CategoryAxisModule,
LegendModule,
LineSeriesModule,
ModuleRegistry,
NumberAxisModule,
} from "ag-charts-community";
import { getData } from "./data";
const WOMEN: AgBarSeriesOptions = {
type: "bar",
xKey: "year",
yKey: "women",
yName: "Women",
grouped: true,
};
const MEN: AgBarSeriesOptions = {
type: "bar",
xKey: "year",
yKey: "men",
yName: "Men",
grouped: true,
};
const PORTIONS: AgLineSeriesOptions = {
type: "line",
xKey: "year",
yKey: "portions",
yName: "Portions",
yKeyAxis: "ySecondary",
};
const BAR_AND_LINE: AgCartesianSeriesOptions[] = [
{ ...WOMEN, type: "bar" },
{ ...MEN, type: "bar" },
{ ...PORTIONS, type: "line" },
];
const AREA_AND_BAR: AgCartesianSeriesOptions[] = [
{ ...PORTIONS, type: "area" },
{ ...WOMEN, type: "bar" },
{ ...MEN, type: "bar" },
];
ModuleRegistry.registerModules([
AreaSeriesModule,
BarSeriesModule,
CategoryAxisModule,
LineSeriesModule,
NumberAxisModule,
LegendModule,
]);
const options: AgCartesianChartOptions = {
data: getData(),
title: {
text: "Fruit & Vegetable Consumption",
},
series: BAR_AND_LINE,
axes: {
y: {
type: "number",
position: "left",
title: {
text: "Adults Who Eat 5 A Day (%)",
},
},
ySecondary: {
type: "number",
position: "right",
title: {
text: "Portions Consumed (Per Day)",
},
},
},
};
options.container = document.getElementById("myChart");
const chart = AgCharts.create(options);
function combinationTypeChange(event: Event) {
const type = (event.target as HTMLInputElement).value as
"area-bar" | "bar-line";
options.series = type === "bar-line" ? BAR_AND_LINE : AREA_AND_BAR;
chart.update(options);
}
if (typeof window !== "undefined") {
// Attach external event handlers to window so they can be called from index.html
(<any>window).combinationTypeChange = combinationTypeChange;
}
Combination Chart Examples Copy Link
See more Combination Chart examples in the AG Charts Gallery.
Bar And Line Combination Chart Example
Histogram And Scatter Combination Chart Example
Horizontal Range Bar And Scatter Combination Chart Example
Radar Line, Radar Area And Nightingale Combination Chart Example
Grouped Category Axis Combination Chart Example
Step Interpolation Combination Chart Example
Bar, Line And Area Combination Chart Example
Stacked Bar And Area Combination Chart Example