Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/modules/annotations/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ export default class Helpers {
w.config.xaxis.convertedCatToNumeric &&
w.labelData.categoryLabels.length
) {
x = w.labelData.categoryLabels.indexOf(String(x)) + 1
const strX = String(x)
x =
w.labelData.categoryLabels.findIndex(
(/** @type {any} */ l) => String(l) === strX,
) + 1
}

const catIndex = w.labelData.labels
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/xaxis-annotations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,5 +633,30 @@ describe('XAxisAnnotations', () => {
expect(labels[0].getAttribute('rel')).toBe('0')
expect(labels[1].getAttribute('rel')).toBe('1')
})

it('should render annotation line for numeric x value on line chart with simple array data (regression #5198)', () => {
// Regression test: in 5.10.4, annotations with numeric x values on line charts
// using simple array data (convertedCatToNumeric=true) were not rendered because
// getStringX() used indexOf(String(x)) which failed when categoryLabels are numbers.
chart = createChartWithOptions({
chart: { type: 'line' },
series: [{ data: [10, 20, 30, 40, 50] }],
annotations: {
xaxis: [
{
x: 3,
borderColor: '#ff0000',
},
],
},
})

const line = chart.w.globals.dom.baseEl.querySelector(
'.apexcharts-xaxis-annotations line'
)
// The annotation line must be present (was missing in 5.10.4 due to regression)
expect(line).not.toBeNull()
expect(line.getAttribute('stroke')).toBe('#ff0000')
})
})
})
Loading