Constant Line
Axis Constant Lines are components under ChartXY Axis, which users can create and control freely.
They highlight a single coordinate on 1 axis by projecting a line across the whole chart.


// Creation of an axis constant line
const constantLine = axis.addConstantLine()
.setValue(5)
Stroke color
constantLine.setStrokeStyle(new SolidLine({
thickness: 1,
fillStyle: new SolidFill({ color: ColorRGBA(255, 0, 0) })
}))
For more details about style API, please see Styles, colors and fonts.
Draw order
Constant lines can be drawn either above series, or below series.
// constant line above series
const constantLine1 = axis.addConstantLine(true)
// constant line below series
const constantLine2 = axis.addConstantLine(false)
User interactions
By default, Constant line has built-in user interactions that allow user to move it around. These can be disabled with setDefaultMouseInteractions:
// Disable default user interactions
constantLine.setDefaultMouseInteractions(false)
Custom user interactions
Custom user interactions can be implemented using the Events API:
constantLine.onMouseClick((_, event) => {
console.log('user clicked constant line', event)
})
Disable highlighting
constantLine.setHighlightOnHover(false)
Dashed stroke
constantLine.setStrokeStyle((stroke) => new DashedLine({
fillStyle: stroke.getFillStyle(),
thickness: stroke.getThickness(),
pattern: StipplePatterns.Dashed,
}))