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

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

问题描述

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

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

小提琴示例

    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;
  });
});

为了使代码更易于理解,您可以创建一个 series 变量,然后在调用 highcharts 函数之前对其进行排序.这在此处进行了演示.

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天全站免登陆