Sort the series data for every X-Axis in Highcharts

后端 未结 1 1470
渐次进展
渐次进展 2020-12-19 15:00

I need to sort the data of series from largest to smallest for every series.

Sample fiddle

    series: [{
        name: \'John\',
        data: [{
           


        
相关标签:
1条回答
  • 2020-12-19 15:48

    You can use the sort function. It can be applied like that:

    series.forEach(function(name){
      name.data.sort(function (a,b) {
        if(a.y < b.y) {
          return 1;
        } else if (a.y > b.y) {
          return -1;
        }
        return 0;
      });
    });
    

    To make the code more understandable you can create a series variable and then sort it before calling the highcharts function. This is demonstrated here.

    0 讨论(0)
提交回复
热议问题