echarts饼图制作

效果图

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 1.导包 -->
    <script src="./echarts.js"></script>
</head>

<body>
    <!-- 2.写HTML结构 -->
    <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
    <div id="main" style="width: 600px;height:400px;"></div>

    <script>
        /* 3.初始化配置 */
        //3.1 创建图表
        // 基于准备好的dom,初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        //3.2 设置图表样式
        // 指定图表的配置项和数据
        var option = {
            //背景颜色
            //backgroundColor: '#2c343c',
            //标题
            // title: {
            //     text: '饼图',
            //     left: 'center',
            //     top: 20,
            //     textStyle: {
            //         color: '#ccc'
            //     }
            // },
            //鼠标移入提示
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b} : {c} ({d}%)'
            },
            //设置每一个数据颜色
            color: ['#006cff', '#006c00', '#ed8884', '#ff9f7f', '#0096ff', '#9fe6b8', '#006cff'],
            //左下角指示器
            // visualMap: {
            //     show: true,
            //     min: 80,
            //     max: 600,
            //     inRange: {
            //         colorLightness: [0, 1]
            //     }
            // },
            //图表内容
            series: [
                {
                    name: '访问来源',
                    type: 'pie',
                    //中间空心圆
                    radius: [10, 110],
                    center: ['50%', '50%'],
                    data: [
                        { value: 335, name: '湖北' },
                        { value: 110, name: '云南' },
                        { value: 160, name: '北京' },
                        { value: 180, name: '山东' },
                        { value: 180, name: '河北' },
                        { value: 160, name: '江苏' },
                        { value: 200, name: '浙江' },
                        { value: 280, name: '四川' }
                    ].sort(function (a, b) { return a.value - b.value; }),
                    roseType: 'radius',
                    //文字颜色  默认显示当前数据自身颜色,如果设置就会覆盖
                    // label: {
                    //     color: 'rgba(255, 255, 255, 0.3)'
                    // },
                    //线条颜色
                    // labelLine: {
                    //     lineStyle: {
                    //         color: 'rgba(255, 255, 255, 0.3)'
                    //     },
                    //     smooth: 0.2,
                    //     length: 5,
                    //     length2: 10
                    // },
                    //内容颜色
                    // itemStyle: {
                    //     color: '#c235ff',
                    //     shadowBlur: 200,
                    //     shadowColor: 'rgba(0, 0, 0, 0.5)'
                    // },

                    animationType: 'scale',
                    animationEasing: 'elasticOut',
                    animationDelay: function (idx) {
                        return Math.random() * 200;
                    }
                }
            ]
        };
        //3.3 加载图表
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    </script>
</body>

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值