123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <template>
- <div :class="className" :style="{height:height,width:width}" />
- </template>
- <script>
- import echarts from 'echarts'
- require('echarts/theme/macarons') // echarts theme
- import resize from './mixins/resize'
- import { debounce } from '@/utils'
- // eslint-disable-next-line no-unused-vars
- const animationDuration = 6000
- export default {
- mixins: [resize],
- props: {
- className: {
- type: String,
- default: 'chart'
- },
- width: {
- type: String,
- default: '100%'
- },
- height: {
- type: String,
- default: '350px'
- },
- autoResize: {
- type: Boolean,
- default: true
- },
- contrastData: {
- type: Object,
- required: true
- }
- },
- data() {
- return {
- chart: null
- }
- },
- watch: {
- contrastData: {
- deep: true,
- handler(val) {
- this.setOptions(val)
- console.log('watch拿到的val', val)
- }
- }
- },
- mounted() {
- this.$nextTick(() => {
- this.initChart()
- })
- },
- beforeDestroy() {
- if (!this.chart) {
- return
- }
- this.chart.dispose()
- this.chart = null
- },
- methods: {
- initChart() {
- this.chart = echarts.init(this.$el, 'macarons')
- this.setOptions(this.contrastData)
- // console.log('methods拿到的pieDeptData', this.pieDeptData)
- },
- setOptions({ lastData, thisData, text, thisMinData, days } = {}) {
- this.chart.setOption({
- title: {
- text: text + '月维修同期对比',
- subtext: ''
- },
- tooltip: {
- trigger: 'axis'
- },
- legend: {
- data: ['去年', '今年']
- },
- toolbox: {
- show: true,
- feature: {
- dataZoom: {
- yAxisIndex: 'none'
- },
- dataView: { readOnly: false },
- magicType: { type: ['line', 'bar'] },
- restore: {},
- saveAsImage: {}
- }
- },
- xAxis: {
- type: 'category',
- name: '日期',
- boundaryGap: false,
- data: days
- },
- yAxis: {
- type: 'value',
- name: '元',
- axisLabel: {
- formatter: '{value}'
- }
- },
- grid: [
- { top: '25%', left: '15%' }
- ],
- series: [
- {
- name: '去年',
- type: 'line',
- // data: [11, 11, 15, 13, 12, 13, 10, 9, 11, 3],
- data: lastData,
- markPoint: {
- data: [
- // { type: 'max', name: '最大值' },
- // { type: 'min', name: '最小值' }
- ]
- },
- markLine: {
- data: [
- { type: 'average', name: '平均值' }
- ]
- }
- },
- {
- name: '今年',
- type: 'line',
- // data: [1, 5, 2, 5, 3, 2, 0, 9, 6, 7],
- data: thisData,
- markPoint: {
- data: [
- // { name: '周最低', value: 5, xAxis: 1, yAxis: 2 }
- // { type: 'max', name: '最大值' },
- // { type: 'min', name: '最小值' }
- ]
- },
- markLine: {
- data: [
- { type: 'average', name: '平均值' },
- [{
- symbol: 'none',
- x: '90%',
- yAxis: 'max'
- }, {
- symbol: 'circle',
- label: {
- normal: {
- position: 'start',
- formatter: '最大值'
- }
- },
- type: 'max',
- name: '最高点'
- }]
- ]
- }
- }
- ]
- })
- }
- }
- }
- </script>
|