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

1647596431(1).jpg
<div id="echarts"></div>
            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+'<br />级别分值范围:'+(item.seriesIndex)*value+' ~ '+(item.seriesIndex+1)*value+"<br/>分值:"+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);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。