Cross Lines are lines or shaded areas in a chart that denote additional information or thresholds, making them useful for data analysis.
Adding Cross Lines Copy Link
To add a Cross Line at a specific data value on an axis, use the crossLines property in the axis options.
A Cross Line can either be a line or a range, and multiple Cross Lines can be added to a single axis.
import {
AgChartOptions,
AgCharts,
CategoryAxisModule,
CrossLinesModule,
LegendModule,
LineSeriesModule,
ModuleRegistry,
NumberAxisModule,
} from "ag-charts-community";
import { getData } from "./data";
ModuleRegistry.registerModules([
CategoryAxisModule,
CrossLinesModule,
LegendModule,
LineSeriesModule,
NumberAxisModule,
]);
const options: AgChartOptions = {
data: getData(),
series: [
{
type: "line",
xKey: "month",
yKey: "temp",
},
],
axes: {
x: {
type: "category",
title: {
text: "Month",
},
crossLines: [
{
type: "range",
range: ["Jun", "Sep"],
},
],
},
y: {
type: "number",
title: {
text: "Temperature (°C)",
},
crossLines: [
{
type: "line",
value: 11,
},
],
},
},
};
options.container = document.getElementById("myChart");
const chart = AgCharts.create(options);
export function getData() {
return [
{
month: "Jan",
temp: 5.5,
},
{
month: "Feb",
temp: 6.1,
},
{
month: "Mar",
temp: 7.4,
},
{
month: "Apr",
temp: 9.2,
},
{
month: "May",
temp: 13.3,
},
{
month: "Jun",
temp: 15.5,
},
{
month: "Jul",
temp: 18.5,
},
{
month: "Aug",
temp: 18.4,
},
{
month: "Sep",
temp: 14.5,
},
{
month: "Oct",
temp: 12.1,
},
{
month: "Nov",
temp: 8.4,
},
{
month: "Dec",
temp: 3.6,
},
];
}
{
axes: {
y: {
position: 'left',
type: 'number',
crossLines: [
{
type: 'line',
value: 11,
},
],
},
x: {
position: 'bottom',
type: 'category',
crossLines: [
{
type: 'range',
range: ['Jun', 'Sep'],
},
],
},
},
}In this configuration:
- A
lineis displayed on the vertical axis at value 11. - A
rangeis displayed on the horizontal axis between June and September. - The
valueorrangevalues should be the same types as those displayed in the axis.
Customising Cross Lines Copy Link
import {
AgChartOptions,
AgCharts,
CrossLinesModule,
LegendModule,
LineSeriesModule,
ModuleRegistry,
NumberAxisModule,
UnitTimeAxisModule,
} from "ag-charts-community";
import { getData } from "./data";
ModuleRegistry.registerModules([
CrossLinesModule,
LegendModule,
LineSeriesModule,
NumberAxisModule,
UnitTimeAxisModule,
]);
const options: AgChartOptions = {
data: getData(),
series: [
{
type: "line",
xKey: "date",
yKey: "petrol",
yName: "Petrol",
},
{
type: "line",
xKey: "date",
yKey: "diesel",
yName: "Diesel",
},
],
axes: {
x: {
type: "unit-time",
title: {
text: "Date",
},
crossLines: [
{
type: "range",
range: [new Date(2019, 4, 1), new Date(2019, 6, 1)],
strokeWidth: 0,
fill: "#7290C4",
fillOpacity: 0.4,
label: {
text: "Price Peak",
position: "top",
fontSize: 14,
fill: "#7290C4",
fillOpacity: 0.4,
cornerRadius: 4,
border: {
stroke: "#7290C4",
},
},
},
],
},
y: {
type: "number",
title: {
text: "Price in pence",
},
crossLines: [
{
type: "line",
value: 142.45,
stroke: "#7290C4",
lineDash: [6, 12],
label: {
text: "142.4",
position: "right",
fontSize: 12,
color: "#000000",
},
},
{
type: "line",
value: 133.8,
stroke: "#7290C4",
lineDash: [6, 12],
label: {
text: "133.8",
position: "right",
fontSize: 12,
color: "#01c185",
},
},
{
type: "line",
value: 135.35,
stroke: "#D21E75",
lineDash: [2, 4],
label: {
text: "135.3",
position: "right",
fontSize: 12,
color: "#000000",
},
},
{
type: "line",
value: 123.97,
stroke: "#D21E75",
lineDash: [2, 4],
label: {
text: "124.0",
position: "right",
fontSize: 12,
color: "#01c185",
},
},
],
},
},
};
options.container = document.getElementById("myChart");
const chart = AgCharts.create(options);
// Source: https://www.gov.uk/government/statistical-data-sets/oil-and-petroleum-products-weekly-statistics
export function getData() {
return [
{ date: new Date(2019, 0, 7), petrol: 125.27, diesel: 136.33 },
{ date: new Date(2019, 0, 14), petrol: 124.53, diesel: 135.47 },
{ date: new Date(2019, 0, 21), petrol: 124.12, diesel: 135.46 },
{ date: new Date(2019, 0, 28), petrol: 124.29, diesel: 135.35 },
{ date: new Date(2019, 1, 4), petrol: 124.13, diesel: 135.43 },
{ date: new Date(2019, 1, 11), petrol: 123.97, diesel: 135.63 },
{ date: new Date(2019, 1, 18), petrol: 124.05, diesel: 135.73 },
{ date: new Date(2019, 1, 25), petrol: 124.22, diesel: 135.66 },
{ date: new Date(2019, 2, 4), petrol: 124.72, diesel: 136.25 },
{ date: new Date(2019, 2, 11), petrol: 125.1, diesel: 136.59 },
{ date: new Date(2019, 2, 18), petrol: 125.48, diesel: 136.85 },
{ date: new Date(2019, 2, 25), petrol: 125.83, diesel: 137.15 },
{ date: new Date(2019, 3, 1), petrol: 126.7, diesel: 137.48 },
{ date: new Date(2019, 3, 8), petrol: 127.75, diesel: 138.08 },
{ date: new Date(2019, 3, 15), petrol: 129.06, diesel: 138.96 },
{ date: new Date(2019, 3, 22), petrol: 129.43, diesel: 139.99 },
{ date: new Date(2019, 3, 29), petrol: 130.36, diesel: 140.6 },
{ date: new Date(2019, 4, 6), petrol: 132.5, diesel: 141.37 },
{ date: new Date(2019, 4, 13), petrol: 132.97, diesel: 141.36 },
{ date: new Date(2019, 4, 20), petrol: 133.51, diesel: 141.82 },
{ date: new Date(2019, 4, 27), petrol: 133.6, diesel: 142.45 },
{ date: new Date(2019, 5, 3), petrol: 133.8, diesel: 142.35 },
{ date: new Date(2019, 5, 10), petrol: 133.64, diesel: 141.4 },
{ date: new Date(2019, 5, 17), petrol: 132.66, diesel: 139.76 },
{ date: new Date(2019, 5, 24), petrol: 131.66, diesel: 137.81 },
{ date: new Date(2019, 6, 1), petrol: 131.49, diesel: 137.55 },
{ date: new Date(2019, 6, 8), petrol: 131.86, diesel: 137.68 },
{ date: new Date(2019, 6, 15), petrol: 132.13, diesel: 137.86 },
{ date: new Date(2019, 6, 22), petrol: 132.81, diesel: 138.21 },
{ date: new Date(2019, 6, 29), petrol: 133.03, diesel: 138.6 },
{ date: new Date(2019, 7, 5), petrol: 133.37, diesel: 138.61 },
{ date: new Date(2019, 7, 12), petrol: 133.36, diesel: 138.59 },
{ date: new Date(2019, 7, 19), petrol: 133.17, diesel: 138.6 },
{ date: new Date(2019, 7, 26), petrol: 133.22, diesel: 138.51 },
{ date: new Date(2019, 8, 2), petrol: 132.86, diesel: 138.29 },
{ date: new Date(2019, 8, 9), petrol: 132.79, diesel: 137.89 },
{ date: new Date(2019, 8, 16), petrol: 131.92, diesel: 137.35 },
{ date: new Date(2019, 8, 23), petrol: 131.78, diesel: 137.52 },
{ date: new Date(2019, 8, 30), petrol: 131.92, diesel: 137.83 },
{ date: new Date(2019, 9, 7), petrol: 131.87, diesel: 137.82 },
{ date: new Date(2019, 9, 14), petrol: 131.91, diesel: 137.89 },
{ date: new Date(2019, 9, 21), petrol: 131.4, diesel: 137.28 },
{ date: new Date(2019, 9, 28), petrol: 130.77, diesel: 136.6 },
{ date: new Date(2019, 10, 4), petrol: 130.56, diesel: 136.38 },
{ date: new Date(2019, 10, 11), petrol: 130.59, diesel: 136.42 },
{ date: new Date(2019, 10, 18), petrol: 130.58, diesel: 136.35 },
{ date: new Date(2019, 10, 25), petrol: 130.32, diesel: 136.08 },
{ date: new Date(2019, 11, 2), petrol: 129.81, diesel: 135.79 },
{ date: new Date(2019, 11, 9), petrol: 129.75, diesel: 135.79 },
{ date: new Date(2019, 11, 16), petrol: 129.33, diesel: 135.56 },
{ date: new Date(2019, 11, 23), petrol: 129.16, diesel: 135.81 },
{ date: new Date(2019, 11, 30), petrol: 129.96, diesel: 136.54 },
];
}
{
crossLines: [
{
type: 'range',
range: [new Date(2019, 4, 1), new Date(2019, 6, 1)],
strokeWidth: 0,
fill: '#7290C4',
fillOpacity: 0.4,
label: {
text: 'Price Peak',
position: 'top',
fontSize: 14,
},
},
],
}In this configuration:
- Properties such as
stroke,strokeWidth, andfillare used to customise the Cross Line. - A label is added, customised and positioned in relation to the Cross Line.
Polar Axes Cross Lines Copy Link
Cross Lines are also available for Polar Axes. These have the same configuration as the Cartesian Cross Lines.
Polar Cross Lines are not included in CrossLinesModule. Register PolarCrossLinesModule separately when using module imports.
import {
AgChartOptions,
AgCharts,
AngleCategoryAxisModule,
AnimationModule,
ContextMenuModule,
CrosshairModule,
LegendModule,
ModuleRegistry,
PolarCrossLinesModule,
RadarLineSeriesModule,
RadiusNumberAxisModule,
} from "ag-charts-enterprise";
import { getData } from "./data";
ModuleRegistry.registerModules([
AngleCategoryAxisModule,
AnimationModule,
CrosshairModule,
PolarCrossLinesModule,
LegendModule,
RadarLineSeriesModule,
RadiusNumberAxisModule,
ContextMenuModule,
]);
const options: AgChartOptions = {
data: getData(),
title: {
text: "Skill Analysis",
},
series: [
{
type: "radar-line",
angleKey: "skill",
radiusKey: "value",
},
],
axes: {
angle: {
type: "angle-category",
shape: "circle",
crossLines: [
{
type: "range",
range: ["Technical Skills", "Communication"],
label: {
text: "Valuable Skills",
},
},
],
},
radius: {
type: "radius-number",
shape: "circle",
crossLines: [
{
type: "line",
value: 6,
stroke: "red",
label: {
text: "Minimal\nRequirement",
positionAngle: 180,
},
},
],
},
},
};
options.container = document.getElementById("myChart");
const chart = AgCharts.create(options);
export function getData() {
return [
{ skill: "Technical Skills", value: 8 },
{ skill: "Problem Solving", value: 8 },
{ skill: "Communication", value: 7 },
{ skill: "Team Player", value: 6 },
{ skill: "Punctuality", value: 5 },
{ skill: "Meeting Deadlines", value: 9 },
];
}
{
axes: {
angle: {
type: 'angle-category',
shape: 'circle',
crossLines: [
{
type: 'range',
range: ['Technical Skills', 'Communication'],
label: {
text: 'Valuable Skills',
},
},
],
},
radius: {
type: 'radius-number',
shape: 'circle',
crossLines: [
{
type: 'line',
stroke: 'red',
value: 6,
label: {
text: 'Minimal\nRequirement',
positionAngle: 180,
},
},
],
},
},
} API Reference Copy Link
- type required
'line' - Renders the Cross Line as a single line positioned at `value`.
- value required
AxisValue - The data value at which the line should be positioned.
- id
string - A user-supplied identifier for the Cross Line, surfaced as `crossLineId` in callback and event params. Defaults to an internally generated identifier.
- enabled
boolean - Whether to show the Cross Line.
- stroke
AgCssColorOrRef - The colour of the stroke for the lines. A colour string, or a theme-colour reference object.
- strokeWidth
PixelSize - The width in pixels of the stroke for the lines.
- strokeOpacity
Opacity - The opacity of the stroke for the lines.
- lineDash
PixelSize[] - Defines how the line stroke is 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.
- label
AgBaseCrossLineLabelOptions - Configuration for the Cross Line label.
- listeners
AgCrossLineListeners - A map of event names to listeners.
- type required
'line' - Renders the Cross Line as a single line positioned at `value`.
- value required
AxisValue - The data value at which the line should be positioned.
- id
string - A user-supplied identifier for the Cross Line, surfaced as `crossLineId` in callback and event params. Defaults to an internally generated identifier.
- enabled
boolean - Whether to show the Cross Line.
- stroke
AgCssColorOrRef - The colour of the stroke for the lines. A colour string, or a theme-colour reference object.
- strokeWidth
PixelSize - The width in pixels of the stroke for the lines.
- strokeOpacity
Opacity - The opacity of the stroke for the lines.
- lineDash
PixelSize[] - Defines how the line stroke is 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.
- label
AgBaseCrossLineLabelOptions - Configuration for the Cross Line label.
- listeners
AgCrossLineListeners - A map of event names to listeners.
- type required
'range' - Renders the Cross Line as a shaded band spanning `range`.
- range required
[AxisValue, AxisValue] - The `[start, end]` data values bounding the shaded region.
- fill
CssColor - The colour to use for the fill of the range.
- fillOpacity
Opacity - The opacity of the fill for the range.
- id
string - A user-supplied identifier for the Cross Line, surfaced as `crossLineId` in callback and event params. Defaults to an internally generated identifier.
- enabled
boolean - Whether to show the Cross Line.
- stroke
AgCssColorOrRef - The colour of the stroke for the lines. A colour string, or a theme-colour reference object.
- strokeWidth
PixelSize - The width in pixels of the stroke for the lines.
- strokeOpacity
Opacity - The opacity of the stroke for the lines.
- lineDash
PixelSize[] - Defines how the line stroke is 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.
- label
AgBaseCrossLineLabelOptions - Configuration for the Cross Line label.
- listeners
AgCrossLineListeners - A map of event names to listeners.
- type required
'range' - Renders the Cross Line as a shaded band spanning `range`.
- range required
[AxisValue, AxisValue] - The `[start, end]` data values bounding the shaded region.
- fill
CssColor - The colour to use for the fill of the range.
- fillOpacity
Opacity - The opacity of the fill for the range.
- id
string - A user-supplied identifier for the Cross Line, surfaced as `crossLineId` in callback and event params. Defaults to an internally generated identifier.
- enabled
boolean - Whether to show the Cross Line.
- stroke
AgCssColorOrRef - The colour of the stroke for the lines. A colour string, or a theme-colour reference object.
- strokeWidth
PixelSize - The width in pixels of the stroke for the lines.
- strokeOpacity
Opacity - The opacity of the stroke for the lines.
- lineDash
PixelSize[] - Defines how the line stroke is 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.
- label
AgBaseCrossLineLabelOptions - Configuration for the Cross Line label.
- listeners
AgCrossLineListeners - A map of event names to listeners.