Question

I have a chart with multiple series for which I have a button that resets the yAxis to a specific amount. I would like to set this specific amount to be the 85th percentile of the yAxis values. Is there a way to calculate this? jsfiddle example: http://jsfiddle.net/inadcod/TynwP/

Was it helpful?

Solution

Very strange that you wish to do this on the client, you could very easily sort and get the value of the 85th percentile on the server where you are actually sending the data from and use it as a max value for the y axis.

Anyway, you can access the data values using the series.points object array, this contains all the points for the given series, it has many properties of which point.y seems to be of your interest. Loop through all these and store them in another array for convenience and sort this new array. take the length of the array and multiple by the factor you wish to (0.85) and this is the index of the element a.k.a. 85th percentile. Set the min of the given yAxis using this value

var yData = [];
$.each(chart.series[0].points, function() {
    yData.push(this.y);
});
var sortedY = sort(yData);
var eightyFifthPercentile = sortedY[Math.floor(sortedY.length * 0.85)];

alert(eightyFifthPercentile); 

http://jsfiddle.net/jugal/HkS2Y/

OTHER TIPS

You can do it this way:

var yAxis = chart.yAxis[0];
var extremes = yAxis.getExtremes();
yAxis.setExtremes(extremes.min, extremes.dataMax * 0.85);

See demo here: http://jsfiddle.net/gyavJ/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top