highslide-software/highcharts.com — Issue #662: Excessive looping in Highstocks with close points in large dataset (leads to stack overflow / non-responsive script)
Author: shiftyp
Created: 2011-12-21 20:18:46+00:00
State: open

[Here](http://jsfiddle.net/WGHrQ/) is a JSFiddle to reproduce the issue. If you want to spare your browser, here is code that reproduces the problem:

``` javascript
var data = [
[Date.UTC(1990, 0, 1), 2],
[Date.UTC(2005, 0, 1, 1, 1, 1, 1), 1],
[Date.UTC(2005, 0, 1, 1, 1, 1, 2), 2]
];

$(function() {
var chart = new Highcharts.StockChart({

chart: {
renderTo: 'container'
},
series: [{
name: 'Stack Overflow',
data: data
}]
});
});
```

It occurs when you have two points that have very close x-values, in a dataset where the total distance between the first and last point is very large. I belive this issue was introduced in b8a547c8e5b7512a7c33d4dd8b50f38a80b04ce9 when [code was added to find the closest distance between two points for a series](https://github.com/highslide-software/highcharts.com/commit/b8a547c8e5b7512a7c33d4dd8b50f38a80b04ce9#L0R10276). This value is used later in [setAxisSize](https://github.com/highslide-software/highcharts.com/blob/b8a547c8e5b7512a7c33d4dd8b50f38a80b04ce9/js/parts/Chart.js#L1337) method to set the closestPointRange for each xAxis, and that value is used later in the [ordinalAxisPlugin](https://github.com/highslide-software/highcharts.com/blob/master/js/parts/OrdinalAxis.js#L277) to set the tickInterval for the axis. With a small tickInterval, and a dataset where the distance between the min and max is many times greater than that interval, there is a potential for a long running loop. It seems to me that the axis should take into account both the closest point distance and the distance between the min and max when determining the tick interval in the case where it is not set explicitly.