<template> <ve-line :data="chartData" :title="title" :settings="chartSettings"/> </template> <script> import { getDayTime } from '@/utils/dateutils' import { alarmStaticByDay } from '@/api/dataStatics' export default { name: 'AlarmByDays', data() { this.title = { text: '7日报警趋势' } this.chartSettings = { labelMap: { 'alarmWells': '报警井数', 'alarmTimes': '报警次数' }, metrics: ['alarmTimes', 'alarmWells'], dimension: ['date'] } return { listQuery: { deviceType: '', beginTime: '', endTime: '' }, chartData: { columns: ['date', 'alarmTimes', 'alarmWells'], rows: [] } } }, mounted() { // this.fetchData() // 模拟数据 this.chartData.rows = [ { 'date': '9月20日', 'alarmTimes': 1393, 'alarmWells': 1093 }, { 'date': '9月21日', 'alarmTimes': 3530, 'alarmWells': 3230 }, { 'date': '9月22日', 'alarmTimes': 2923, 'alarmWells': 2623 }, { 'date': '9月23日', 'alarmTimes': 1723, 'alarmWells': 1423 }, { 'date': '9月24日', 'alarmTimes': 3792, 'alarmWells': 3492 }, { 'date': '9月25日', 'alarmTimes': 4593, 'alarmWells': 4293 } ] }, methods: { fetchData() { const beginTime = getDayTime(new Date().getTime() - 24 * 7 * 60 * 60 * 1000).Format('yyyy-MM-dd hh:mm:ss') const endTime = new Date().Format('yyyy-MM-dd hh:mm:ss') this.listQuery.beginTime = beginTime this.listQuery.endTime = endTime alarmStaticByDay(this.listQuery).then(response => { this.chartData.rows = response.data }) } } } </script>