0
votes

I want to set minimum and maximum values in an axis in highcharts. I have tried min, max, ceiling and floor attributes. They change the range of axis.

Link to the JS Fiddle

yAxis: {
    floor: 0,
    ceiling: 40,
    title: {
        text: 'Percentage'
    }
},

series: [{
    data: [0, 1, -5, 2, 3, 5, 8, 5, 50, 14, 25, 54]
}]

I want the data to be modified automatically based on the minimum/floor and maximum/ceiling values declared in the axis declaration.

For example, if in the above mentioned case, the last and last 4th elements of series should be automatically modified to 40 and the 3rd element to 0.

Is there any attribute of highchart using which I can achieve this without manually checking all the series elements to fall between the min and max values?

1

1 Answers

3
votes

No I don't think there is no such a function. Highcharts does not alter your data, it just changes what is displayed. But checking for values beneath or above certain thresholds is really simple:

var data = [0, 1, -5, 2, 3, 5, 8, 5, 50, 14, 25, 54];
var max = 40;
var min = 0;

// clamping "by hand"
console.log( data.map(function(d) { return Math.max(min, Math.min(max, d)); }) );

If you use a library like lodash: these often provide a clamp function so you could write

console.log( _.map(data, function(d) { return _.clamp(d, min, max) }