Highcharts export-data: null in series.data after addPoint
getCSV throws 'Cannot read properties of null (reading y)' after addPoint inserts a point into a cropped series
HTML
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<script src="https://code.highcharts.com/stock/modules/export-data.js"></script>
<div id="container"></div>
<pre id="out"></pre>
CSS
#container { min-width: 300px; max-width: 800px; height: 300px; margin: 1em auto; }
JavaScript
const H = 3600e3;
const chart = Highcharts.stockChart('container', {
navigator: { enabled: false },
scrollbar: { enabled: false },
rangeSelector: { enabled: false },
xAxis: { min: 500 * H, max: 600 * H },
series: [{
data: Array.from({ length: 1000 }, (_, i) => [i * H, i])
}]
});
// Insert a point in the middle of the series, outside the visible range.
// Series.addPoint splices a null into series.data for it, and since the
// point is cropped out it is never generated, so the null stays.
chart.series[0].addPoint([10.5 * H, 1]);
// Throws: Cannot read properties of null (reading 'y')
// Also reproducible via the export menu -> Download CSV
try {
const csv = chart.exporting.getCSV();
document.getElementById('out').textContent = 'OK, ' + csv.split('\n').length + ' rows';
} catch (e) {
document.getElementById('out').textContent = e.stack;
}