美文网首页
echarts 饼图:自定义展示labelLine及中心放图片

echarts 饼图:自定义展示labelLine及中心放图片

作者: 牛会骑自行车 | 来源:发表于2022-11-16 08:32 被阅读0次
效果图 👇(展示排名最高的四组数据线) 自定义labelLine.png

上代码 ↓

methods: {
initPie () {
               data.map((n) => {
                this.pieData.push({
                    value: n.value,
                    name: n.name,
                    label: {
                        show: false
                    },
                    labelLine: {
                        show: false
                    }
                })
            })

            let sortArr = this.pieData
                .sort(function (a, b) {
                    return b.value - a.value
                })
                .slice(0, this.labelNum)

            this.pieData.map((m) => {
                for (let i = 0; i < sortArr.length; i++) {
                    if (sortArr[i].name === m.name) {
                        m.label = {
                            show: true
                        }

                        m.labelLine = {
                            show: true
                        }

                        return m
                    }
                }
            })

            this.options = {
                graphic: {
                    elements: [
                        {
                            type: 'image',
                            style: {
                                image,
                                width: this.imageSize,
                                height: this.imageSize
                            },
                            left: 'center',
                            top: 'center'
                        }
                    ]
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    bottom: this.legend.bottom,
                    left: this.legend.left,
                    top: this.legend.top,
                    right: this.legend.right,
                    itemWidth: 16,
                    itemHeight: 8,
                    borderRadius: 5
                },
                series: [
                    {
                        type: 'pie',
                        radius: ['40%', '70%'],
                        center: this.center,
                        label: {
                            normal: {
                                show: false,
                                formatter: '{b} {c}'
                            }
                        },
                        data: this.pieData
                    }
                ]
            }
            this.drawChart()
  }
}

主要是做数据的转换

相关文章

网友评论

      本文标题:echarts 饼图:自定义展示labelLine及中心放图片

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