<template> <div class="inerank-container"> <div :style="{height:'100%',width:'100%'}" ref="myLineRank"></div> </div> </template> <script> export default { props:{ result:{ type:Array, default:[] }, total:{ type:Number, default:0 } }, data() { return {}; }, mounted() { this.init(); }, methods: { init() { let myChart = this.$echarts.init(this.$refs.myLineRank); let dataItemName=[] this.result.forEach(x=>{ dataItemName.push(x.name); x.value=x.rate }) let option = { tooltip: { trigger: "item", formatter: "{a} <br/>{b} : {c} ({d}%)" }, legend: { orient: "vertical", left: "70%", //图例距离左的距离 top: "15%", //图例上下居中 data: dataItemName }, calculable: true, graphic: [ { type: "text", left: "23%", top: "30%", style: { text: this.total, textAlign: "center", fill: "#A2A4A7", //文字的颜色 fontSize: 40, width:120, fontFamily: "pingfangR" } }, { type: "text", left: "22%", top: "48%", style: { text: "累计成交订单", textAlign: "center", fill: "#A2A4A7", //文字的颜色 fontSize: 14, fontFamily: "pingfangR" } } ], series: [ { center: ["30%", "40%"], name: "订单来源", type: "pie", radius: ["50%", "70%"], itemStyle: { normal: { label: { show: false }, labelLine: { show: false }, borderWidth: 2, borderColor: "#fff", color: function(params) { //自定义颜色 var colorList = [ "#FFB822", "#34BFA3", "#FD3995", "#5D78FF", "#8e44ad" ]; return colorList[params.dataIndex]; } }, emphasis: { label: { show: true, center: ["30%", "40%"], textStyle: { fontSize: "20", fontFamily: "pingfangR" } } } }, data: this.result } ] }; myChart.setOption(option); } } }; </script> <style> .inerank-container { height: 100%; width: 100%; } </style>