对Highcharts中每个X轴的系列数据进行排序 [英] Sort the series data for every X-Axis in Highcharts

查看:1623
本文介绍了对Highcharts中每个X轴的系列数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将每个系列的系列数据从大到小排序。

样品小提琴

 系列:[{
name:'John ',
data:[{
y:1},{y:2},{y:3},{y:4},{y:5
}]
},{
name:'Jane',
data:[{
y:5},{y:4},{y:3},{y:2},{y: 1
}]
},{
名称:'Joe',
data:[{
y:5},{y:2},{y:3 },{y:4},{y:1
}]
}]


解决方案

您可以使用排序功能。它可以这样应用:

  series.forEach(function(name){
name.data.sort(函数(a,b){
if(ay< by){
return 1;
} else if(ay> by){
return -1;
}
返回0;
});
});

为了让代码更易于理解,您可以创建一个系列变量,然后在调用 highcharts 函数之前进行排序。这已在此处显示。


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

Sample fiddle

    series: [{
        name: 'John',
        data: [{
            y: 1}, {y: 2}, {y: 3}, {y: 4}, {y: 5
        }]
    }, {
        name: 'Jane',
        data: [{
            y: 5}, {y: 4}, {y: 3}, {y: 2}, {y: 1
        }]
    }, {
        name: 'Joe',
        data: [{
            y: 5}, {y: 2}, {y: 3}, {y: 4}, {y: 1
        }]
    }]

解决方案

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.

这篇关于对Highcharts中每个X轴的系列数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆