官网定义颜色网址
效果
代码
<template>
<div :id="id"></div>
</template>
<script>
import echarts from 'echarts';
import theme from './theme.json';
import { mapGetters } from 'vuex';
export default {
props: ['id', 'pieData'],
data() {
return {
charts: null,
pieNames: [],
imageUrl: require('@/assets/chart/chartalarm.png'),
color: [
'rgba(226, 59, 65,1)',
'rgba(201, 20, 34, 1)',
'rgba(185, 40, 41, 1)',
'rgba(253, 173, 56, 1)',
'rgba(253, 195, 68, 1)',
'rgba(251, 105, 164, 1)',
],
};
},
watch: {
pieData(val) {
this.pieData.forEach((ele) => {
this.pieNames.push(ele.name);
});
if (val.length > 0) {
this.$nextTick(() => {
if (this.theme === 'white-theme') {
this.imageUrl = require('@/assets/chart/chartalarm2.png');
this.initChart(this.id, theme.whitetheme);
} else {
this.imageUrl = require('@/assets/chart/chartalarm.png');
this.initChart(this.id, theme.blacktheme);
}
});
}
},
theme: {
handler(val) {
this.charts.dispose();
if (val === 'white-theme') {
this.$nextTick(() => {
this.imageUrl = require('@/assets/chart/chartalarm2.png');
this.initChart(this.id, theme.whitetheme);
});
} else {
this.$nextTick(() => {
this.imageUrl = require('@/assets/chart/chartalarm.png');
this.initChart(this.id, theme.blacktheme);
});
}
},
},
},
computed: {
...mapGetters(['theme']),
},
methods: {
initChart(id, themeType) {
echarts.registerTheme('slef-theme', themeType);
this.charts = echarts.init(document.getElementById(id), 'slef-theme');
let option = {
color: this.color,
graphic: {
elements: [
{
type: 'image',
style: {
image: this.imageUrl,
width: 130,
height: 130,
},
left: 'center',
top: 'center',
},
],
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c} ({d}%)',
position: 'inside',
},
legend: {
bottom: 'bottom',
data: this.pieNames,
},
series: [
{
name: '报警分析',
type: 'pie',
radius: ['43%', '55%'],
data: this.createChartData(),
},
],
};
this.charts.setOption(option, true);
},
createChartData() {
let pieChartData = this.pieData;
let data = [];
for (var i = 0; i < pieChartData.length; i++) {
data.push({
value: pieChartData[i].value,
name: pieChartData[i].name,
itemStyle: {
normal: {
shadowBlur: 30,
shadowColor: this.color[i],
},
},
});
}
return data;
},
},
};
</script>
theme.json 文件
{
"blacktheme": {
"legend": {
"textStyle": {
"color": "#fff"
}
}
},
"whitetheme": {
"legend": {
"textStyle": {
"color": "#262626"
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)