| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <template>
- <div class="chart" ref="chart"></div>
- </template>
- <script>
- import * as echarts from 'echarts'
- import { fontSize } from '@/views/groupPage/util'
- export default {
- name: 'designAndConsChart', //设计施工综合图表
- props: {
- chartData: {
- default: () => {
- return {
- legendData: ['监理', '施工'],
- xData: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
- spvData: [120, 132, 101, 134, 90, 230, 210, 182, 191, 234, 290, 330],
- consData: [220, 182, 191, 234, 290, 330, 310, 201, 154, 190, 330, 410]
- }
- }
- }
- },
- data() {
- return { myChart: null }
- },
- watch: {
- chartData(val) {
- this.$nextTick(() => {
- this.initialChart()
- })
- }
- },
- mounted() {
- this.$nextTick(() => {
- this.initialChart()
- })
- //图表大小自适应
- 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 legendData = this.chartData.legendData
- let xData = this.chartData.xData
- let spvData = this.chartData.spvData
- let consData = this.chartData.consData
- let option = {
- grid: {
- left: '5%',
- right: '5%',
- top: '20%',
- 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: 'right',
- y: '10',
- icon: 'inherit',
- itemWidth: 15,
- itemHeight: 10,
- textStyle: {
- color: '#FFFFFF'
- },
- data: legendData
- },
- xAxis: [
- {
- type: 'category',
- boundaryGap: true,
- axisLabel: {
- color: '#FFFFFF',
- interval: 0
- },
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- splitLine: {
- show: false
- },
- data: 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)'
- }
- }
- }
- ],
- series: [
- {
- name: '监理',
- type: 'line',
- stack: '总量',
- symbol: 'circle',
- symbolSize: 6,
- showSymbol: false,
- smooth: true,
- itemStyle: {
- color: '#FFD553'
- },
- lineStyle: {
- color: '#FFD553',
- width: 1
- },
- areaStyle: {
- color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
- {
- offset: 0,
- color: 'rgba(7,44,90,0.3)'
- },
- {
- offset: 1,
- color: 'rgba(255, 213, 83, 1)'
- }
- ])
- },
- data: spvData
- },
- {
- name: '施工',
- type: 'line',
- stack: '总量',
- symbol: 'circle',
- symbolSize: 6,
- showSymbol: false,
- smooth: true,
- itemStyle: {
- color: '#0EA7FF'
- },
- lineStyle: {
- color: '#0EA7FF',
- width: 1
- },
- areaStyle: {
- color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
- {
- offset: 0,
- color: 'rgba(7,44,90,0.3)'
- },
- {
- offset: 1,
- color: 'rgba(14, 167, 255, 1)'
- }
- ])
- },
- data: consData
- }
- ]
- }
- 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>
|