<template> <ve-pie :data="chartData" :settings="chartSetting" :legend="legend" :title="title"/> </template> <script> import { deviceStaticByStatus } from '@/api/dataStatics' import { alarmNowStatic } from '@/api/dataStatics' export default { data() { return { chartSetting: { label: { show: false }, labelLine: { show: false } }, chartData: { columns: ['onlineStatus', 'deviceCount'], rows: [] }, title: { text: '设备报警情况统计' }, extend: { series: { label: { show: true, position: 'outside', formatter: '{b}:{c}' } } }, chartSettings: { labelMap: { 'onlineStatus': '在线状态', 'deviceCount': '设备数量' }, dimension: 'onlineStatus', metrics: 'deviceCount' }, legend: { right: 10 } } }, mounted() { // this.fetchData() this.getAlarmCount() }, methods: { // 当前报警数 getAlarmCount() { alarmNowStatic().then(response => { this.chartData.rows = [ { 'onlineStatus': '在线', 'deviceCount': 297 }, { 'onlineStatus': '报警', 'deviceCount': response.data.total } ] }) }, fetchData() { deviceStaticByStatus().then(response => { const data = response.data this.chartData.rows = [ { 'onlineStatus': '在线', 'deviceCount': data.online }, { 'onlineStatus': '报警', 'deviceCount': data.offline } ] }) } } } </script>