0

I'm using highcharts, which uses a data series to plot the chart similar to this:

series:

[{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]

I know that I can use a Json file to feed the dataset so, how can I get its highest value?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Digelim
  • 98
  • 2
  • 9

2 Answers2

0

This is how you can get the highest value in the data array.

data = [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]

var highest_value = Math.max.apply(Math, data);
console.log(highest_value) //216.4
Alex Pan
  • 4,341
  • 8
  • 34
  • 45
0

Considering this is JSON, you need to parse it first:

var dataset = JSON.parse(rawDataset);

Then you can use the Math.max function with the array applied as the arguments to filter the largest value:

var largest = Math.max.apply(Math, dataset[0].data);