美文网首页
echarts一个界面多个饼图简单封装

echarts一个界面多个饼图简单封装

作者: 用心为你 | 来源:发表于2020-04-13 11:15 被阅读0次

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

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}

    .circleWrap {
        overflow: hidden;
    }

    .circleWrap .circle {
        /* float: left; */
        width: 200px;
        float: left;


    }
</style>

</head>

<body>
<div class="circleWrap">
<div id="lamp" style="height: 174px;" class="circle"></div>
<div id="landscape" style="height: 174px;" class="circle"></div>
<div id="saving" style="height: 208px;" class="circle"></div>
</div>

<script src="./echarts.min.js"></script>
        
<script type="text/javascript">
    var lampOpenCount = 3;
    var convertCtrlOpen = 1;
    var saveEnergy = 1;
    var lampCount = 2;
    var convert = 2;
    var noIntelLight = 4;

    drawPieChart('lamp', 1, lampOpenCount, lampCount);
    drawPieChart('landscape', 3, convertCtrlOpen, convert);
    drawPieChart('saving', 2, saveEnergy, noIntelLight);

    function drawPieChart(id, type, openCount, count) {
        var myChart = echarts.init(document.getElementById(id));
        var option = {
            tooltip: {
                // show: false
            },
            legend: {
                show: false
            },
            color: ['#efae25', '#f0f2f5'],
            series: [{
                // name: type === 1 ? '亮灯率' : '节电率',
                name: type === 1 ? '亮灯率' : type === 2 ?'节电率':type === 3?'自定义':'',
                type: 'pie',
                radius: type === 1 ? ['60%', '80%'] : ['48%', '68%'],
                center: ['50%', '50%'],
                hoverAnimation: false,
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        position: 'center',
                        textStyle: {
                            fontSize: '16',
                            color: '#999'
                        },
                        formatter: "{a} \n {d}%"
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data: [{
                    value: openCount,
                    label: {
                        normal: {
                            show: true
                        }
                    },
                    itemStyle: {
                        emphasis: {
                            color: '#efae25'
                        }
                    },
                },
                {
                    value: count - openCount,
                    label: {
                        normal: {
                            show: false
                        }
                    },
                    itemStyle: {
                        emphasis: {
                            color: '#f0f2f5'
                        }
                    }
                }
                ]
            }]
        };;

        if (option && typeof option === "object") {
            myChart.setOption(option, true);
        }
    }
</script>
    </body>

</html>

相关文章

网友评论

      本文标题:echarts一个界面多个饼图简单封装

      本文链接:https://www.haomeiwen.com/subject/uucgmhtx.html