Echarts3实例 环形图

前言

    环形图本质上就是饼图,我们把饼图的半径设置成阶段范围内的值域,饼图就变成了环形图。

实现效果

在这里插入图片描述

实现代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        html,body{
            height: 100%;
        }
        *{
            margin: 0px;
            height: 0px;
        }
        #chartDiv{
            width: 650px;
            height: 370px;
            border: 1px solid red;
        }
    </style>
    <script src="js/echarts.min.js"></script>
</head>
<body>
    <div id="chartDiv"></div>
    <script>
        var chartDiv = echarts.init(document.getElementById('chartDiv'));
        var option = {
            title: {
                text: '各阶段工程数量及占比',
                left: 'center',
                textStyle:{
                    fontSize:14
                }
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b}: {c} ({d}%)",
                extraCssText:"height:43px;"//设置tooltip的高度
            },

            series: [
                {
                    name:'访问来源',
                    type:'pie',
                    center: ['50%', '60%'],//控制位置
                    radius: ['40%', '60%'],//控制圆环的宽度
                    avoidLabelOverlap: true,//防止重叠
                    label: {
                        normal: {
                            formatter: '{a|{b}}{abg|}\n{hr|}\n  {b|数量:}{c}  {per|{d}%}  ',//空格也起作用
                            backgroundColor: '#eee',
                            borderColor: '#aaa',
                            borderWidth: 1,
                            borderRadius: 2,
                            rich: {
                                a: {
                                    color: '#999',
                                    lineHeight: 20,
                                    align: 'center'
                                },
                                hr: {
                                    borderColor: '#aaa',
                                    width: '100%',
                                    borderWidth: 0.5,
                                    height: 0
                                },
                                b: {
                                    fontSize: 12,
                                    lineHeight: 20
                                },
                                per: {
                                    color: '#eee',
                                    backgroundColor: '#334455',
                                    padding: [2, 4],
                                    borderRadius: 2
                                }
                            }
                        },
                        emphasis: {
                            show: true,
                            textStyle: {
                                fontSize: '14',
                            }
                        }
                    },
                    labelLine: {
                        normal: {
                            show: true,
                        }
                    },
                    data:[
                        {value:335, name:'直达'},
                        {value:679, name:'营销广告'},
                        {value:1548, name:'搜索引擎'}
                    ]
                }
            ]
        };
        chartDiv.setOption(option);
    </script>
</body>
</html>
可以使用以下代码来使用 echarts 画双层环形: ```javascript // 引入 echarts import echarts from 'echarts'; // 初始化 echarts 实例 const myChart = echarts.init(document.getElementById('myChart')); // 配置数据 const option = { title: { text: '双层环形', subtext: '示例', left: 'center' }, tooltip: { trigger: 'item', formatter: '{a} <br/>{b}: {c} ({d}%)' }, legend: { orient: 'vertical', left: 10, data: ['层级一', '层级二'] }, series: [ { name: '层级一', type: 'pie', selectedMode: 'single', radius: [0, '30%'], label: { position: 'inner' }, labelLine: { show: false }, data: [ { value: 335, name: '直接访问' }, { value: 679, name: '邮件营销' }, { value: 1548, name: '搜索引擎' } ] }, { name: '层级二', type: 'pie', radius: ['40%', '55%'], label: { formatter: '{a|{a}}{abg|}\n{hr|}\n {b|{b}:}{c} {per|{d}%} ', backgroundColor: '#eee', borderColor: '#aaa', borderWidth: 1, borderRadius: 4, shadowBlur: 3, shadowOffsetX: 2, shadowOffsetY: 2, shadowColor: '#999', padding: [0, 7], rich: { a: { color: '#999', lineHeight: 22, align: 'center' }, hr: { borderColor: '#aaa', width: '100%', borderWidth: 0.5, height: 0 }, b: { fontSize: 16, lineHeight: 33 }, per: { color: '#eee', backgroundColor: '#334455', padding: [2, 4], borderRadius: 2 } } }, data: [ { value: 335, name: '直接访问' }, { value: 310, name: '邮件营销' }, { value: 234, name: '联盟广告' }, { value: 135, name: '视频广告' }, { value: 1048, name: '百度' }, { value: 251, name: '谷歌' }, { value: 147, name: '必应' }, { value: 102, name: '其他' } ] } ] }; // 使用刚指定的配置项和数据显示表。 myChart.setOption(option); ``` 这是一个简单的示例,你可以根据自己的需求进行修改和定制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值