| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <template>
- <div class="chart" ref="chart"></div>
- </template>
- <script>
- import * as echarts from 'echarts'
- import { fontSize } from '@/views/groupPage/util'
- export default {
- name: 'inspectionsNumChart', //上报统计图表
- props: {
- chartData: {}
- },
- data() {
- return { myChart: null }
- },
- watch: {
- chartData(val) {
- this.$nextTick(() => {
- this.initialChart()
- })
- }
- },
- mounted() {
- //图表大小自适应
- window.addEventListener('resize', this.onResize)
- },
- methods: {
- destroyChart() {
- if (this.myChart != null) {
- this.myChart.dispose()
- this.myChart = null
- }
- },
- onResize() {
- if (this.myChart) {
- this.myChart.resize()
- }
- },
- initialChart() {
- this.destroyChart()
- let option = {
- grid: {
- left: '5%',
- right: '5%',
- bottom: '5%',
- containLabel: true
- },
- tooltip: {
- show: true,
- confine: true,
- borderWidth: 0,
- textStyle: {
- color: '#fff'
- },
- backgroundColor: 'rgba(50,50,50,0.7)',
- trigger: 'axis',
- axisPointer: {
- lineStyle: {
- type: 'solid',
- color: 'rgba(255, 255, 255, 0.3)'
- }
- }
- },
- legend: {
- show: true,
- x: 'center',
- y: '10',
- icon: 'inherit',
- itemHeight: 10,
- itemWidth: 16,
- textStyle: {
- color: '#FFFFFF'
- },
- data: ['累计次数', '每月次数']
- },
- xAxis: [
- {
- type: 'category',
- boundaryGap: true,
- axisLabel: {
- color: '#FFFFFF'
- },
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- splitLine: {
- show: false
- },
- data: this.chartData.xData
- }
- ],
- yAxis: [
- {
- type: 'value',
- name: '累计次数',
- nameTextStyle: {
- color: '#FFFFFF'
- },
- axisLabel: {
- color: '#FFFFFF'
- },
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- splitLine: {
- show: true,
- lineStyle: {
- color: 'rgba(255, 255, 255, 0.2)'
- }
- }
- },
- {
- type: 'value',
- name: '每月次数',
- position: 'right',
- nameTextStyle: {
- color: '#FFFFFF'
- },
- axisLabel: {
- color: '#FFFFFF'
- },
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- splitLine: {
- show: true,
- lineStyle: {
- color: 'rgba(255, 255, 255, 0.2)'
- }
- }
- }
- ],
- series: [
- {
- name: '累计次数',
- type: 'line',
- symbol: 'circle',
- symbolSize: 8,
- showSymbol: false,
- smooth: true,
- itemStyle: {
- color: '#FFD553'
- },
- lineStyle: {
- color: '#FFD553',
- width: 2
- },
- data: this.chartData.total
- },
- {
- name: '每月次数',
- type: 'bar',
- barWidth: 12,
- itemStyle: {
- color: '#0EA7FF'
- },
- data: this.chartData.everydayTimes
- }
- ]
- }
- this.creatChart(option, this.$refs.chart)
- },
- creatChart(option, ref) {
- this.myChart = echarts.init(ref) //this.$refs.chart
- this.myChart.resize()
- this.myChart.setOption(option, {
- notMerge: true
- })
- }
- },
- beforeDestroy() {
- window.removeEventListener('resize', this.onResize)
- this.destroyChart()
- }
- }
- </script>
- <style lang='scss' scoped>
- .chart {
- height: 100%;
- width: 100%;
- }
- </style>
|