123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <template>
- <div :id="baseConfig.ids" :style="{ width: width, height: height }"></div>
- </template>
- <script>
- import resize from "./resize";
- export default {
- props: {
- data: {
- default: () => ({ name: [], seriesData: [] }),
- },
- width: {
- type: String,
- default: "100%",
- },
- height: {
- type: String,
- default: "100%",
- },
- baseConfig: {
- default: function () {
- return {
- ids: "EchartsBar",
- title: "",
- unit: "人",
- };
- },
- },
- },
- mixins: [resize],
- data() {
- return {
- chart: null,
- // color: ['rgba(143,223,254,0.4)', 'rgba(0,168,255,0.4)'],
- colorConfig: [
- //颜色配置
- // { code: "1", name: "已处理", color: ["#23E490", "#00AE63"] }, //周界
- // { code: "0", name: "未处理", color: ["#FFB500", "#E9CC75"] }, // 火灾
- // { code: "100001", name: "人员报警", color: ["#A1A9FF", "#707CFF"] }, // 人员
- // { code: "100002", name: "周界防护", color: ["#23E490", "#00AE63"] }, //周界
- // { code: "100003", name: "火灾报警", color: ["#FFB500", "#E9CC75"] }, // 火灾
- // { code: "100004", name: "泄漏监测", color: ["#00E0C3", "#4AC6E2"] }, // 泄漏
- { code: "1", name: "已处理", color: "#00FFCC" }, //周界
- { code: "0", name: "未处理", color: "#00B0B0" }, // 火灾
- { code: "100001", name: "人员定位", color: "#00E1FF" }, // 人员
- { code: "100002", name: "周界入侵", color: "#00B387" }, //周界
- { code: "100003", name: "火灾监测", color: "#00FFCC" }, // 火灾
- { code: "100004", name: "激光云台", color: "#00B0B0" }, // 泄漏
- ],
- };
- },
- mounted() {
- this.drawChart();
- },
- beforeDestroy() {
- if (!this.chart) {
- return;
- }
- this.chart.dispose();
- this.chart = null;
- },
- watch: {
- data: {
- //深度监听,可监听到对象、数组的变化
- handler(newVal) {
- this.$nextTick(() => {
- this.drawChart();
- });
- },
- deep: true,
- },
- },
- methods: {
- drawChart() {
- this.chart = this.$echarts.init(document.getElementById(this.baseConfig.ids));
- let option = {
- title: {
- show: false,
- },
- grid: {
- left: "3%",
- right: "4%",
- top: "10%",
- bottom: "15%",
- containLabel: true,
- },
- // toolbox: {
- // feature: {
- // magicType: { show: true, type: ["line", "bar"] },
- // restore: { show: true },
- // saveAsImage: { show: true },
- // },
- // iconStyle: {
- // borderColor: "#fff",
- // },
- // emphasis: {
- // iconStyle: {
- // borderColor: "#409EFF",
- // },
- // },
- // },
- tooltip: {
- trigger: "axis",
- axisPointer: {
- type: "line",
- lineStyle: {
- type: "dashed",
- },
- },
- padding: 10,
- textStyle: {
- fontSize: 12,
- },
- },
- color: ["#00E1FF", "#00B387", "#00FFCC", "#00B0B0"],
- legend: {
- bottom: 0,
- itemWidth: 14,
- textStyle: {
- color: "#fff",
- },
- },
- yAxis: [
- {
- type: "category",
- data: this.data.name,
- inverse: true,
- axisLabel: {
- textStyle: {
- color: "#fff",
- },
- margin: 10,
- // interval: 0,
- },
- axisTick: {
- show: false,
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: "#99FFFA",
- },
- },
- },
- ],
- xAxis: {
- axisTick: {
- show: true,
- },
- axisLabel: {
- textStyle: {
- color: "#fff",
- },
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: "#99FFFA",
- },
- },
- splitLine: {
- show: false,
- },
- minInterval: 1,
- position: "top",
- },
- series: this.data.seriesData.map((item, index) => {
- return {
- name: item.name,
- stack: "total",
- type: "bar",
- // barWidth: 24,
- barMaxWidth: 30,
- itemStyle: {
- normal: {
- // borderColor: '#7dd8fe',
- color: (params) => {
- return this.colorConfig.find((c) => c.code === item.code).color;
- },
- opacity: 0.8,
- },
- emphasis: {
- opacity: 1,
- },
- },
- data: item.data,
- };
- }),
- };
- this.chart.setOption(option, true);
- },
- },
- };
- </script>
|