echarts 饼图叠加态--统计成绩及格分

1647596431(1).jpg
            let list = [];
            const max = 150;
            const value = 15;//每一级15分值
            let rows = [
                {name: '语文',score:parseInt(Math.random()*max)},{name: '数学',score:parseInt(Math.random()*max)},{name: '物理',score:parseInt(Math.random()*max)},{name: '化学',score:parseInt(Math.random()*max)},
                {name: '历史',score:parseInt(Math.random()*max)},{name: '生物',score:parseInt(Math.random()*max)},{name: '政治',score:parseInt(Math.random()*max)},{name: '音乐',score:parseInt(Math.random()*max)}
            ];
            let color = [
                "rgb("+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+")",
                "rgb("+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+")",
                "rgb("+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+")",
                "rgb("+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+")",
                "rgb("+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+")",
                "rgb("+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+")",
                "rgb("+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+")",
                "rgb("+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+','+parseInt(Math.random()*255)+")"
            ]
            
            for(var i=0;i<=max/value;i++){
                let rowsCloen = JSON.parse(JSON.stringify(rows));
                rowsCloen = rowsCloen.map((e,index)=>{
                    e.value = value;
                    e.itemStyle = {
                        color:!(e.score<=(i+1)*value&&e.score<=i*value)?color[index]:"#ddd"
                    }
                    return e;
                })
                list.push({
                    name: '图表'+i,
                    type: 'pie',
                    radius: [(i)*8+'%', (i+1)*8+'%'],
                    label: {
                        position: 'inner',
                        fontSize: 14
                    },
                    labelLine: {
                        show: false
                    },
                    emphasis: {
                        focus: 'series'
                    },
                    itemStyle:{
                        normal:{
                            label:{
                                show:false
                            }
                        }
                    },
                    data: rowsCloen
                })
            }
            let option = {
                tooltip: {
                    trigger: 'item',
                    formatter: function(item,index,a){
                        return item.name+'
级别分值范围:'+(item.seriesIndex)*value+' ~ '+(item.seriesIndex+1)*value+"
分值:"+item.data.score; } }, toolbox: { show: true, feature: { mark: { show: true }, dataView: { show: true, readOnly: false }, restore: { show: true }, saveAsImage: { show: true } } }, series: list }; const dome = echarts.init(document.getElementById("echarts")); dome.setOption(option);

你可能感兴趣的:(echarts 饼图叠加态--统计成绩及格分)