让标题和价格换行 数据为0的不展示处理
drawPie(id, channelData) {
this.chart = this.$echarts.init(document.getElementById(id));
console.log(this.chart);
let color = ["#5b9bd5", "#ed7d31", "#a9d18e", "#ffc000", "#06d3c4"];
this.chart.setOption({
name: "访问来源",
type: "pie",
radius: "30%",
center: ["30%", "55%"],
label: {
position: "inner",
fontSize: 14,
formatter: function(params) {
var str=`${params.name}:¥${params.value} `
if(params.value>0){
return str.split(":").join("\n")
}
},
show: true
},
series: [
{
name: "今日收银概况",
type: "pie",
radius: "55%",
data: channelData
}
],
color: ["#f89588", "#63b2ee", "#76da91", "#7cd6cf",'#f8cb7f'],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: "rgba(0, 0, 0, 0.5)"
}
}
});
},
getData() {
getHomeData().then(res => {
if (res.code == 200) {
this.showDetail = false;
this.detailData = res.data;
this.$nextTick(() => {
let channel = [];
for (let i = 0; i < res.data.payment_channel.length; i++) {
if (res.data.payment_channel[i].pay_type == 1) {
channel.push({
name: "现金",
value: res.data.payment_channel[i].payment?res.data.payment_channel[i].payment:null
});
} else if (res.data.payment_channel[i].pay_type == 2) {
channel.push({
name: "支付宝",
value: res.data.payment_channel[i].payment?res.data.payment_channel[i].payment:null
});
} else if (res.data.payment_channel[i].pay_type == 3) {
channel.push({
name: "微信",
value: res.data.payment_channel[i].payment?res.data.payment_channel[i].payment:null
});
} else if (res.data.payment_channel[i].pay_type == 4) {
channel.push({
name: "银行卡",
value: res.data.payment_channel[i].payment?res.data.payment_channel[i].payment:null
});
} else if (res.data.payment_channel[i].pay_type == 5) {
channel.push({
name: "POS",
value: res.data.payment_channel[i].payment?res.data.payment_channel[i].payment:null
});
}
}
this.drawPie("chartPie", channel);
});
}
});
},