用echarts来实现多重环形图

老规矩先看效果:

然后就是贴代码啦:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>echarts.js案例一</title>
    <script type="text/javascript" src='echarts.js'></script>
</head>
<body>
    <div id="chart" style="width:400px;height:400px;"></div>
</body>
<script type="text/javascript">
    // 初始化图表标签
    var myChart = echarts.init(document.getElementById('chart'));
    var BorderWidth = '10';
    //反方向剩下部分的样式
    var placeHolderStyle = {
        normal: {
            label: {
                show: false,
                position: "center"
            },
            labelLine: {
                show: false
            },
            color: "rgba(0,0,0,0)",
            borderColor: "rgba(0,0,0,0)",
            borderWidth: 0
        },
        emphasis: {
            color: "#dedede",
            borderColor: "#dedede",
            borderWidth: 0
        }
    };
    var options = {
        backgroundColor: '#000',
        color: ['#53f1f2', '#4ebefd', '#30ed9d', '#faa234', "#fff"],
        legend: {
            show: true,
            orient:'vertical',
            left:'left',
            top:'middle',
            data: ['正常', '次要', '警告','重要','严重'],
            textStyle:{
                color:'#fff',
                fontSize:16
            }
        },
        series: [{
            name: '正常',
            type: 'pie',
            clockWise: true, //顺时加载
            hoverAnimation: false, //鼠标移入变大
            radius: [100, 101],
            itemStyle: {
                normal: {
                    label: {
                        show: false,
                        position: 'outside'
                    },
                    labelLine: {
                        show: false,
                        length: 100,
                        smooth: 0.5
                    },
                    borderWidth: BorderWidth,
                    shadowBlur: 40,
                    borderColor: "#53f1f2",
                    shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
                }
            },
            data: [{
                value: 7,
                name: '70%'
            },
             {
                value: 3,
                name: '',
                itemStyle: placeHolderStyle
            }
            ]
        }, {
            name: '次要',
            type: 'pie',
            clockWise: true,
            hoverAnimation: false,
            radius: [80, 81],
            itemStyle: {
                normal: {
                    label: {
                        show: false
                    },
                    labelLine: {
                        show: false,
                        length: 100,
                        smooth: 0.5
                    },
                    borderWidth: BorderWidth,
                    shadowBlur: 40,
                    borderColor: "#4ebefd",
                    shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
                }
            },
            data: [{
                value: 6,
                name: '60%'
            }, 
            {
                value: 4,
                name: '',
                itemStyle: placeHolderStyle
            }
            ]
        },  {
            name: '警告',
            type: 'pie',
            clockWise: true,
            hoverAnimation: false,
            radius: [60, 61],
            itemStyle: {
                normal: {
                    label: {
                        show: false
                    },
                    labelLine: {
                        show: false,
                        length: 100,
                        smooth: 0.5
                    },
                    borderWidth: BorderWidth,
                    shadowBlur: 40,
                    borderColor: "#30ed9d",
                    shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
                }
            },
            data: [{
                value: 5,
                name: '40%'
            }, 
            {
                value: 5,
                name: '',
                itemStyle: placeHolderStyle
            }
            ]
        },  {
            name: '重要',
            type: 'pie',
            clockWise: true,
            hoverAnimation: false,
            radius: [40, 41],
            itemStyle: {
                normal: {
                    label: {
                        show: false
                    },
                    labelLine: {
                        show: false,
                        length: 100,
                        smooth: 0.5
                    },
                    borderWidth: BorderWidth,
                    shadowBlur: 40,
                    borderColor: "#faa234",
                    shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
                }
            },
            data: [{
                value: 5,
                name: '30%'
            }, 
            {
                value: 5,
                name: '',
                itemStyle: placeHolderStyle
            }
            ]
        }, {
            name: '严重',
            type: 'pie',
            clockWise: true,
            hoverAnimation: false,
            radius: [20, 21],
            itemStyle: {
                normal: {
                    label: {
                        show: false
                    },
                    labelLine: {
                        show: false,
                        length: 100,
                        smooth: 0.5
                    },
                    borderWidth: BorderWidth,
                    shadowBlur: 40,
                    borderColor: "#fff",
                    shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
                }
            },
            data: [{
                value: 4,
                name: '30%'
            }, 
            {
                value: 6,
                name: '',
                itemStyle: placeHolderStyle
            }
            ]
        }]
    };
    myChart.setOption(options);
</script>
</html>

 

  • 5
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
实现多重环形的方法可以使用Echarts中的Polar(极坐标)和Bar(柱状)来实现。在Echarts中,可以通过设置多个系列来创建多重环形。每个系列代表一个环,通过设置各个环的半径、角度和颜色等属性,可以实现多重环形效果。 首先,需要引入Echarts库,然后创建一个容器来承载表。接着,通过配置项来设置表的样式和数据,其中包括设置多个系列的属性。例如,设置各个环的半径、角度、颜色和数据等。 下面是一个示例代码,展示了如何使用Echarts实现多重环形: ```javascript // 引入Echarts库 import echarts from 'echarts'; // 创建容器 const chartContainer = document.getElementById('chart-container'); // 初始化表 const chart = echarts.init(chartContainer); // 配置项 const option = { // 设置表类型为极坐标 polar: {}, // 设置多个系列,每个系列代表一个环 series: [ { type: 'bar', data: [/* 数据 */], // 设置第一个环的半径和角度 radius: ['0%', '30%'], angle: [0, 360], // 设置第一个环的颜色和样式 itemStyle: { color: 'blue', }, }, { type: 'bar', data: [/* 数据 */], // 设置第二个环的半径和角度 radius: ['30%', '60%'], angle: [0, 360], // 设置第二个环的颜色和样式 itemStyle: { color: 'green', }, }, // 可以继续添加更多的系列 ], }; // 使用配置项生成表 chart.setOption(option); ``` 使用上述代码,你可以根据自己的需求设置每个环的半径、角度、颜色和数据等属性,从而实现多重环形
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浩星

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值