jhbigscreen/src/components/project-overview-chart2.js

193 lines
6.7 KiB
JavaScript
Raw Normal View History

2023-08-10 01:16:23 +08:00
import Vue from 'vue'
Vue.component("project-overview-chart2", {
template: `
<div style="position: relative">
<div :style="{'height': height+'px'}" ref="warningPieChart">
</div>
<div class="chart-gif chart-overview-gif"></div>
</div>
`,
props: {
typedata:{
type: Array,
},
height:{
type:Number
},
text:{
type:String
},
maintitle:{
type:[String,Number],
default:''
},
sp:{
type:String,
default:"\n"
}
},
data() {
return {
active:0,
option:{}
}
},
mounted(){
this.init()
},
methods: {
init(){
this.getChartData()
},
getChartData(){
//品类金额占比 饼图
var chChartPie = echarts.init(this.$refs.warningPieChart);
this.echartPie(chChartPie,this.typedata)
},
echartPie(chChart,chartData){
let newPromise = new Promise((resolve) => {
resolve()
})
//然后异步执行echarts的初始化函数
newPromise.then(() => {
var total_datas = 0;
var data = [];
var legendData = [];
var color = ['#4974ff','#52aef7','#6863d7','#1d5d89','#20e6ff','#67feef']
for (let i = 0; i <chartData.length ; i++) {
total_datas += Number(chartData[i].value);
legendData.push(chartData[i].name)
data.push(
{
value: chartData[i].value,
name: chartData[i].name,
itemStyle: {
normal: {
//颜色渐变
color: color[i]
},
},
},
)
}
let legendOption = {
top: "center",
left:240,
orient: "horizontal",
icon: "rect",
itemWidth: 12,
itemGap: 20,
textStyle: {
fontSize: 14,
rich: {
name: {
color: "#c3dbfd",
padding: [10, 5, 25, 5],
},
percent: {
color: "#4676FD",
padding: [0, 5, 0, 5],
},
},
},
formatter: (name)=> {
let res = chartData.filter((v) => v.name === name);
let percent = ((res[0].value * 100) / total_datas).toFixed(1);
if(total_datas==0){
percent=0;
}
return "{name| " + name + "}"+this.sp+"{percent|" + res[0].value + "}{percent|" + percent + "%}";
},
};
this.option = {
color:["#4B7CFD","#58B8FF","#6A67DD","#2A77A9","#1CEDFC","#69FDF4","#58AAF7","#6B63DC","#2977AB","#1DE6FE"],
title: {
text: this.maintitle||total_datas,
subtext: this.text,
x: "85",
y: "89",
textStyle: {
color: "#0dd2fd",
fontSize: 24,
fontWeight: "bold",
align: "center",
width: "200px",
},
subtextStyle: {
color: "#a5b5f0",
fontSize: 12,
align: "center",
},
},
tooltip: {
trigger: 'item',
formatter: "{b} <br/>{c} ({d}%)"
},
legend: [
{
right: 10,
data: legendData,
align: "left",
...legendOption,
},
],
series: [
{
name: "品类金额占比",
type: "pie",
center: ["115.5", "113.5"],
radius: ["55", "70"],
data: data,
label: {
show: false,
},
itemStyle: {
normal: {
borderWidth: 5,
borderColor: "#051a36"
}
},
},
{
name: "外边框",
type: "pie",
clockWise: false, //顺时加载
hoverAnimation: false, //鼠标移入变大
center: ["115.5", "113.5"],
radius: ["75", "75.5"],
label: {
normal: {
show: false,
},
},
data: [
{
value: 9,
name: "",
itemStyle: {
normal: {
borderWidth: 3,
borderColor: "#152c65",
},
},
},
],
},
],
}
chChart.setOption(this.option);
window.onresize = chChart.resize;
})
},
},
})