Skip to content

Commit 7dd405b

Browse files
authored
Merge pull request #5201 from apexcharts/copilot/fix-line-chart-annotations-issue
fix: x-axis annotations missing on line/area/scatter charts (5.10.4 regression)
2 parents 03cf4b8 + 41010d0 commit 7dd405b

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/modules/annotations/Helpers.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ export default class Helpers {
300300
w.config.xaxis.convertedCatToNumeric &&
301301
w.labelData.categoryLabels.length
302302
) {
303-
x = w.labelData.categoryLabels.indexOf(String(x)) + 1
303+
const strX = String(x)
304+
x =
305+
w.labelData.categoryLabels.findIndex(
306+
(/** @type {any} */ l) => String(l) === strX,
307+
) + 1
304308
}
305309

306310
const catIndex = w.labelData.labels

tests/unit/xaxis-annotations.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,5 +633,30 @@ describe('XAxisAnnotations', () => {
633633
expect(labels[0].getAttribute('rel')).toBe('0')
634634
expect(labels[1].getAttribute('rel')).toBe('1')
635635
})
636+
637+
it('should render annotation line for numeric x value on line chart with simple array data (regression #5198)', () => {
638+
// Regression test: in 5.10.4, annotations with numeric x values on line charts
639+
// using simple array data (convertedCatToNumeric=true) were not rendered because
640+
// getStringX() used indexOf(String(x)) which failed when categoryLabels are numbers.
641+
chart = createChartWithOptions({
642+
chart: { type: 'line' },
643+
series: [{ data: [10, 20, 30, 40, 50] }],
644+
annotations: {
645+
xaxis: [
646+
{
647+
x: 3,
648+
borderColor: '#ff0000',
649+
},
650+
],
651+
},
652+
})
653+
654+
const line = chart.w.globals.dom.baseEl.querySelector(
655+
'.apexcharts-xaxis-annotations line'
656+
)
657+
// The annotation line must be present (was missing in 5.10.4 due to regression)
658+
expect(line).not.toBeNull()
659+
expect(line.getAttribute('stroke')).toBe('#ff0000')
660+
})
636661
})
637662
})

0 commit comments

Comments
 (0)