How to alter Calc chart data range in a macro

I need to talk to a human about this, having tried AI as well as web trawling; there are so many examples out there, none of which work on my system (Windows 11, LibreOffice version 26.2.0.3)

All I want is to be able to modify the end row of a data series of a chart, from within a macro. It’s not hard to get the current value:
ThisComponent.CurrentController.ActiveSheet.Charts(0).Ranges(0).EndRow
gives the value that I want to change, but assigning a new value to it has no effect.

I’d be most grateful for some help, preferably some sample working code.

Did your web trawling include this page from the Wiki?