echarts单环饼图

在这里插入图片描述

<template>
    <div class="box">
        <div id="echarts" style="width:600px;height:200px;margin:50px auto;"></div>
    </div>
</template>
<script>
import * as echarts from 'echarts';
export default {
    data() {
        return {}
    },
    created() { },
    mounted() {
        this.showEcharts()
    },
    methods: {
        showEcharts() {
            let data1 = {
                text: 200,
                subtext: '设备总数',
                top: "100",
                itemGap: 0,
                legend_data: ["正常", "故障"],
                series_data: [
                    { value: 190, name: '正常' },
                    { value: 10, name: '故障' },

                ]
            };
            this.typeCharts0('echarts', data1)
        },
        typeCharts0(id, summary) {
            let fontColor = '#61646a';
            var chartDom = document.getElementById(id);
            var myChart = echarts.init(chartDom);
            let option = {
                color: ["#009CFF", "#F8276C"],
                title: {
                    text: summary.text,   //标题
                    subtext: summary.subtext,
                    left: "center",
                    top: summary.top,
                    itemGap: summary.itemGap,
                    textBaseline: "middle",
                    textStyle: {
                        color: fontColor,
                        fontFamily: "微软雅黑",
                        fontSize: 24,
                        fontWeight: "normal",
                        lineHeight: 26,
                    },
                },
                tooltip: {  //浮框 (显示数值)
                    trigger: "item",
                    formatter: "{a} <br/>{b}: {c} ({d}%)",
                },
                legend: {
                    orient: 'horizontal',
                    x: 'center',
                    y: 'top',
                    itemGap: 5,
                    itemWidth: 18,
                    itemHeight: 12,
                    textStyle: {
                        color: fontColor,
                        fontSize: 10,
                    },
                    data: summary.legend_data,
                },
                series: [
                    {
                        name: "",
                        type: "pie",
                        radius: ["50%", "70%"],
                        center: ["50%", "60%"],
                        avoidLabelOverlap: false,
                        label: {
                            normal: {
                                show: false,
                                position: "center",
                            },
                            emphasis: {
                                show: false,
                                textStyle: {
                                    fontSize: "20",
                                    fontWeight: "bold",
                                },
                            },
                        },
                        itemStyle: {
                            normal: {
                                label: {
                                    show: false,
                                },
                                labelLine: {
                                    show: false,
                                },
                            },
                            emphasis: {
                                label: {
                                    show: true,
                                    position: "center",
                                    textStyle: {
                                        fontSize: "20",
                                        fontWeight: "bold",
                                    },
                                },
                            },
                        },
                        labelLine: {
                            normal: {
                                show: false,
                            },
                        },
                        data: summary.series_data,
                    },
                ],
            };
            if (summary.font_size) {
                option.title.textStyle.fontSize = summary.font_size;
            }
            option && myChart.setOption(option);
        }
    }
}
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值