We just wrapped up AG Studio Launch Week See what we shipped

JavaScript ChartsCross Lines

Version 14.3.0

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.

{
    axes: {
        y: {
            type: 'number',
            crossLines: [
                {
                    type: 'line',
                    value: 11,
                },
            ],
        },
        x: {
            type: 'category',
            crossLines: [
                {
                    type: 'range',
                    range: ['Jun', 'Sep'],
                },
            ],
        },
    },
}

In this configuration:

  • A line is displayed on the vertical axis at value 11.
  • A range is displayed on the horizontal axis between June and September.
  • The value or range values should be the same types as those displayed in the axis.

Customising Cross Lines Copy Link

{
    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',
                placement: 'top',
                fontSize: 14,
            },
        },
    ],
}

In this configuration:

  • Properties such as stroke, strokeWidth, and fill are used to customise the Cross Line.
  • A label is added, customised and placed in relation to the Cross Line. See Label Placement for more details.

Label Placement Copy Link

Use label.placement to choose where a label sits relative to its Cross Line. The default is top.

{
    axes: {
        x: {
            type: 'time',
            crossLines: [
                {
                    type: 'line',
                    value: new Date(2025, 9, 1),
                    label: { text: 'Launch', placement: 'left-top' },
                },
            ],
        },
        y: {
            type: 'number',
            crossLines: [
                {
                    type: 'range',
                    range: [180, 210],
                    label: { text: 'Baseline', placement: 'inside-top-left' },
                },
            ],
        },
    },
}

In this example:

  • Use the checkboxes to show a line and a range on each axis, and the dropdowns to change their placements. Each dropdown lists the placements that apply to that Cross Line.
  • The first part of a placement names the edge the label sits against, and the second positions it along that edge. For example, top-left sits above the Cross Line aligned to its left, while left-top sits beside its left edge aligned to its top.
  • Some placements apply to only one axis, such as top-left for a y-axis line and left-top for an x-axis line.
  • start and end resolve to left and right, and are mirrored when RTL Layout is enabled.
  • Providing placement as an ordered array lets the label fall back to the next placement when it collides or doesn't fit.

Fitting Long Labels Copy Link

There are a number of ways to handle long labels which do not fit within the series area or exceed a provided maxWidth or maxHeight.

{
    crossLines: [
        {
            type: 'range',
            range: [new Date(2025, 5, 1), new Date(2025, 7, 1)],
            label: {
                text: 'Summer Promotion: Reduced Pricing in All Stores',
                placement: 'inside-top',
                maxWidth: 120,
                maxHeight: 60,
            },
        },
    ],
}

In this example:

  • Use the controls to see how the labels wrap, shrink and truncate.
  • A label that exceeds maxWidth or maxHeight or does not fit within the series area, wraps according to wrapping, shrinks towards minimumFontSize, then is truncated if truncate is enabled. See Series Label Collision Avoidance for details.

Polar Axes Cross Lines Copy Link

Cross Lines are also available for Polar Axes. They share the line and range options of Cartesian Cross Lines, but the label options differ by axis: radius axis labels are positioned with positionAngle, and angle axis labels support the common label options only.

Polar Cross Lines are not included in CrossLinesModule. Register PolarCrossLinesModule separately when using module imports.

{
    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,
                    },
                },
            ],
        },
    },
}

Theming Cross Lines Copy Link

Theme overrides style every Cross Line on an axis type. Add a line or range object to style only the Cross Lines of that type.

{
    theme: {
        overrides: {
            common: {
                axes: {
                    number: {
                        crossLines: {
                            strokeWidth: 2,
                            line: { stroke: '#d62728', lineDash: [4, 4] },
                            range: { fill: '#7290C4', fillOpacity: 0.2 },
                        },
                    },
                },
            },
        },
    },
}

In this configuration:

  • strokeWidth applies to every Cross Line.
  • The line and range options take precedence over the options for every Cross Line, and options set on a Cross Line take precedence over both.

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 AgCartesianCrossLineLabelOptions
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 AgCssColorOrRef
The colour to use for the fill of the range. A colour string, or a theme-colour reference object.
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 AgCartesianCrossLineLabelOptions
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 AgCssColorOrRef
The colour to use for the fill of the range. A colour string, or a theme-colour reference object.
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 '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 AgRadiusCrossLineLabelOptions
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 AgCssColorOrRef
The colour to use for the fill of the range. A colour string, or a theme-colour reference object.
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 AgRadiusCrossLineLabelOptions
Configuration for the Cross Line label.
listeners AgCrossLineListeners
A map of event names to listeners.