首页 > 代码库 > echarts 单选legend 并排序

echarts 单选legend 并排序

 

一、legend 单选设置:

   legend : {
        data : [‘周末双休‘, ‘周末轮休‘, ‘周末补休‘],
        selected : {
            ‘周末轮休‘ : false,
            ‘周末补休‘ : false
        },
        selectedMode : "single"
    }
 
二、排序
    有 arry1, arry2, arry3
 
series : [{
            name : ‘周末双休‘,
            type : ‘bar‘,
            itemStyle : dataStyle,
            data : (function () {
                var data = http://www.mamicode.com/[];
                arry1.sort(function(a,b){
                                  if(a>b)
                                    return -1;      //降序
                                  else
                                   return 1;
 
                                })
                arry1.forEach(function (item) {
                    data.push(parseInt(item))
                })
                return data;
            })()
        }, {
            name : ‘周末轮休‘,
            type : ‘bar‘,
            itemStyle : dataStyle,
            data : (function () {
                var data = http://www.mamicode.com/[];
                arry2.sort(function(a,b){
                  if(a>b)
                    return -1;
                  else
                   return 1;
 
                })
                arry2.forEach(function (item) {
                    data.push(parseInt(item))
                })
                return data;
            })()
        }, {
            name : ‘周末不修‘,
            type : ‘bar‘,
            itemStyle : dataStyle,
            data : (function () {
                var data = http://www.mamicode.com/[];
                arry3.sort(function(a,b){
                      if(a>b)
                        return -1;
                      else
                       return  1;
 
                    })
                arry3.forEach(function (item) {
                    data.push(parseInt(item))
                })
                return data;
            })()
        }
    ]

echarts 单选legend 并排序