8 changed files with 707 additions and 97 deletions
-
22src/api/library.js
-
5src/assets/styles/index.scss
-
2src/components/echart/lineChart.vue
-
221src/components/echart/lineChartMonth.vue
-
267src/components/echart/lineChartQuarter.vue
-
45src/views/map/index.vue
-
55src/views/pageOne/index.vue
-
127src/views/pageThree/index.vue
@ -0,0 +1,221 @@ |
|||||
|
<template> |
||||
|
<div ref="lineMonthContainer" :style="{height:height,width:width}" /> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import * as echarts from 'echarts' |
||||
|
import resize from '@/utils/resizeMixins.js' |
||||
|
export default { |
||||
|
name: 'LineEcharts', |
||||
|
mixins: [resize], |
||||
|
props: { |
||||
|
chartMonthData: { |
||||
|
type: Object, |
||||
|
required: true, |
||||
|
default: () => ({ |
||||
|
timeData: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], |
||||
|
returnData: [], |
||||
|
borrowedData: [] |
||||
|
}) |
||||
|
}, |
||||
|
width: { |
||||
|
type: String, |
||||
|
default: '100%' |
||||
|
}, |
||||
|
height: { |
||||
|
type: String, |
||||
|
default: '100%' |
||||
|
} |
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
chart: null, |
||||
|
timeReMonth: null // 定时器变量 |
||||
|
} |
||||
|
}, |
||||
|
watch: { |
||||
|
chartMonthData: { |
||||
|
deep: true, |
||||
|
immediate: true, |
||||
|
handler(val) { |
||||
|
this.$nextTick(() => { |
||||
|
this.initChart() |
||||
|
}) |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
mounted() { |
||||
|
this.$nextTick(() => { |
||||
|
this.initChart() |
||||
|
}) |
||||
|
this.resetPiechartMonthData() |
||||
|
window.addEventListener('resize', this.__resizeHandler) |
||||
|
}, |
||||
|
beforeDestroy() { |
||||
|
clearInterval(this.timeReMonth) |
||||
|
if (this.chart) { |
||||
|
this.chart.dispose() |
||||
|
this.chart = null |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
resetPiechartMonthData() { |
||||
|
clearInterval(this.timeReMonth) |
||||
|
this.timeReMonth = setInterval(() => { |
||||
|
if (!this.chart) { |
||||
|
return |
||||
|
} |
||||
|
this.chart.clear() |
||||
|
this.initChart() |
||||
|
}, 8000) |
||||
|
}, |
||||
|
initChart() { |
||||
|
const dom = this.$refs.lineMonthContainer |
||||
|
|
||||
|
if (this.chart) { |
||||
|
this.setOptions(this.chartMonthData) |
||||
|
return |
||||
|
} |
||||
|
this.chart = echarts.init(dom, 'dark') |
||||
|
this.setOptions(this.chartMonthData) |
||||
|
}, |
||||
|
setOptions({ timeData = [], returnData = [], borrowedData = [] } = {}) { |
||||
|
const defaultLength = timeData.length || 12 |
||||
|
const defaultData = Array(defaultLength).fill(0) |
||||
|
|
||||
|
const validateData = (data) => { |
||||
|
if (data && data.length === defaultLength) return data |
||||
|
return defaultData |
||||
|
} |
||||
|
|
||||
|
const returnVals = validateData(returnData) |
||||
|
const borrowedVals = validateData(borrowedData) |
||||
|
|
||||
|
this.chart.setOption({ |
||||
|
backgroundColor: '#01103D', |
||||
|
tooltip: { |
||||
|
trigger: 'axis', |
||||
|
axisPointer: { |
||||
|
type: 'cross', |
||||
|
label: { |
||||
|
backgroundColor: '#6a7985' |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
legend: { |
||||
|
top: '4%', |
||||
|
right: '4%', |
||||
|
icon: 'rect', |
||||
|
itemHeight: 6, |
||||
|
itemWidth: 11, |
||||
|
textStyle: { |
||||
|
color: '#339CFF', |
||||
|
fontSize: 18 |
||||
|
}, |
||||
|
data: [ |
||||
|
{ |
||||
|
name: '借出', |
||||
|
icon: 'rect', |
||||
|
textStyle: { |
||||
|
color: '#41A3FF', |
||||
|
fontFamily: 'DingTalk_JinBuTi_Regular' |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
name: '归还', |
||||
|
icon: 'rect', |
||||
|
textStyle: { |
||||
|
color: '#FFD050', |
||||
|
fontFamily: 'DingTalk_JinBuTi_Regular' |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
}, |
||||
|
grid: { |
||||
|
left: '2%', |
||||
|
right: '4%', |
||||
|
bottom: '4%', |
||||
|
containLabel: true |
||||
|
}, |
||||
|
xAxis: [{ |
||||
|
type: 'category', |
||||
|
data: timeData, |
||||
|
axisLabel: { |
||||
|
show: true, |
||||
|
color: '#79B8FF', |
||||
|
fontSize: 16, |
||||
|
fontFamily: 'DingTalk_JinBuTi_Regular' |
||||
|
}, |
||||
|
axisLine: { show: false }, |
||||
|
axisTick: { show: false }, |
||||
|
splitLine: { show: false }, |
||||
|
boundaryGap: false |
||||
|
}], |
||||
|
yAxis: [ |
||||
|
{ |
||||
|
type: 'value', |
||||
|
max: function(value) { |
||||
|
return Math.ceil(value.max + (value.max - value.min) * 0.2) |
||||
|
}, |
||||
|
min: 0, |
||||
|
axisLabel: { |
||||
|
interval: 'auto', |
||||
|
formatter: (value) => Math.round(value), |
||||
|
textStyle: { |
||||
|
color: '#79B8FF', |
||||
|
fontSize: 16, |
||||
|
fontFamily: 'DingTalk_JinBuTi_Regular' |
||||
|
} |
||||
|
}, |
||||
|
axisLine: { show: false }, |
||||
|
axisTick: { show: false }, |
||||
|
splitLine: { |
||||
|
show: true, |
||||
|
lineStyle: { |
||||
|
color: 'rgba(66, 139, 221, 0.2)', |
||||
|
type: 'solid', |
||||
|
opacity: 1, |
||||
|
width: 1 |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
], |
||||
|
series: [ |
||||
|
{ |
||||
|
name: '借出', |
||||
|
type: 'line', |
||||
|
stack: 'Total', |
||||
|
itemStyle: { color: '#41A3FF' }, |
||||
|
lineStyle: { width: 3, color: '#41A3FF' }, |
||||
|
showSymbol: false, |
||||
|
areaStyle: { |
||||
|
opacity: 0.6, |
||||
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
||||
|
{ offset: 0, color: 'rgba(254, 128, 66, 0)' }, |
||||
|
{ offset: 1, color: '#41A3FF' } |
||||
|
]) |
||||
|
}, |
||||
|
data: borrowedVals |
||||
|
}, |
||||
|
{ |
||||
|
name: '归还', |
||||
|
type: 'line', |
||||
|
stack: 'Total', |
||||
|
lineStyle: { width: 3, color: '#FFD14F' }, |
||||
|
showSymbol: false, |
||||
|
itemStyle: { color: '#FFD14F' }, |
||||
|
areaStyle: { |
||||
|
opacity: 0.6, |
||||
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
||||
|
{ offset: 0, color: 'rgba(24, 176, 143, 0)' }, |
||||
|
{ offset: 1, color: '#FFD14F' } |
||||
|
]) |
||||
|
}, |
||||
|
data: returnVals |
||||
|
} |
||||
|
] |
||||
|
}, true) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
@ -0,0 +1,267 @@ |
|||||
|
<template> |
||||
|
<div ref="lineContainer" :style="{height:height,width:width}" /> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import echarts from 'echarts' |
||||
|
import resize from '@/utils/resizeMixins.js' |
||||
|
export default { |
||||
|
name: 'LineEcharts', |
||||
|
mixins: [resize], |
||||
|
props: { |
||||
|
chartQuarterData: { |
||||
|
type: Object, |
||||
|
required: true, |
||||
|
default: function() { |
||||
|
return { |
||||
|
quarterData: ['一季度', '二季度', '三季度', '四季度'], |
||||
|
returnData: [], |
||||
|
borrowedData: [] |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
width: { |
||||
|
type: String, |
||||
|
default: '100%' |
||||
|
}, |
||||
|
height: { |
||||
|
type: String, |
||||
|
default: '100%' |
||||
|
} |
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
chart: null, |
||||
|
option: null, |
||||
|
timeRePie: null |
||||
|
} |
||||
|
}, |
||||
|
watch: { |
||||
|
// 监听季度数据变化 |
||||
|
chartQuarterData: { |
||||
|
deep: true, |
||||
|
immediate: true, |
||||
|
handler(val) { |
||||
|
setTimeout(() => { |
||||
|
this.initChart() |
||||
|
}, 100) |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
beforeDestroy() { |
||||
|
// 清除定时器,防止内存泄漏 |
||||
|
clearInterval(this.timeRePie) |
||||
|
if (!this.chart) { |
||||
|
return |
||||
|
} |
||||
|
this.chart.dispose() |
||||
|
this.chart = null |
||||
|
}, |
||||
|
mounted() { |
||||
|
this.$nextTick(() => { |
||||
|
this.initChart() |
||||
|
}) |
||||
|
window.addEventListener('resize', this.__resizeHandler) |
||||
|
this.resetPiechartQuarterData() |
||||
|
}, |
||||
|
methods: { |
||||
|
resetPiechartQuarterData() { |
||||
|
clearInterval(this.timeRePie) |
||||
|
this.timeRePie = setInterval(() => { |
||||
|
if (!this.chart) { |
||||
|
return |
||||
|
} |
||||
|
this.chart.clear() |
||||
|
this.initChart() |
||||
|
}, 8000) |
||||
|
}, |
||||
|
initChart() { |
||||
|
const dom = this.$refs.lineContainer |
||||
|
if (this.chart) { |
||||
|
this.setOptions(this.chartQuarterData) |
||||
|
return |
||||
|
} |
||||
|
this.chart = echarts.init(dom, 'dark') |
||||
|
this.setOptions(this.chartQuarterData) |
||||
|
}, |
||||
|
setOptions({ quarterData, returnData, borrowedData } = {}) { |
||||
|
const defaultQuarters = ['一季度', '二季度', '三季度', '四季度'] |
||||
|
const quarters = quarterData && quarterData.length ? quarterData : defaultQuarters |
||||
|
const returnVals = returnData && returnData.length ? returnData : [0, 0, 0, 0] |
||||
|
const borrowedVals = borrowedData && borrowedData.length ? borrowedData : [0, 0, 0, 0] |
||||
|
|
||||
|
this.chart.setOption({ |
||||
|
backgroundColor: '#01103D', |
||||
|
tooltip: { |
||||
|
trigger: 'axis', |
||||
|
axisPointer: { |
||||
|
type: 'cross', |
||||
|
label: { |
||||
|
backgroundColor: '#6a7985' |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
legend: { |
||||
|
top: '4%', |
||||
|
right: '4%', |
||||
|
icon: 'rect', |
||||
|
itemHeight: 6, |
||||
|
itemWidth: 11, |
||||
|
textStyle: { |
||||
|
color: '#339CFF', |
||||
|
fontSize: 18 |
||||
|
}, |
||||
|
data: [ |
||||
|
{ |
||||
|
name: '借出', |
||||
|
icon: 'rect', |
||||
|
textStyle: { |
||||
|
color: '#41A3FF', |
||||
|
fontFamily: 'DingTalk_JinBuTi_Regular' |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
name: '归还', |
||||
|
icon: 'rect', |
||||
|
textStyle: { |
||||
|
color: '#FFD050', |
||||
|
fontFamily: 'DingTalk_JinBuTi_Regular' |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
}, |
||||
|
grid: { |
||||
|
left: '2%', |
||||
|
right: '4%', |
||||
|
bottom: '4%', |
||||
|
containLabel: true |
||||
|
}, |
||||
|
xAxis: [{ |
||||
|
type: 'category', |
||||
|
data: quarters, |
||||
|
axisLabel: { |
||||
|
show: true, |
||||
|
color: '#79B8FF', |
||||
|
fontSize: 16, |
||||
|
fontFamily: 'DingTalk_JinBuTi_Regular' |
||||
|
}, |
||||
|
axisLine: { |
||||
|
show: false, |
||||
|
lineStyle: { |
||||
|
width: '1', |
||||
|
color: '#113D72', |
||||
|
type: 'solid' |
||||
|
} |
||||
|
}, |
||||
|
axisTick: { |
||||
|
show: false |
||||
|
}, |
||||
|
splitLine: { |
||||
|
show: false, |
||||
|
lineStyle: { |
||||
|
color: '#333' |
||||
|
} |
||||
|
}, |
||||
|
boundaryGap: false |
||||
|
}], |
||||
|
yAxis: [ |
||||
|
{ |
||||
|
type: 'value', |
||||
|
max: function(value) { |
||||
|
return Math.ceil(value.max + (value.max - value.min) * 0.2) |
||||
|
}, |
||||
|
min: 0, |
||||
|
axisLabel: { |
||||
|
interval: 'auto', |
||||
|
formatter: function(value) { |
||||
|
return Math.round(value) |
||||
|
}, |
||||
|
textStyle: { |
||||
|
color: '#79B8FF', |
||||
|
fontSize: 16, |
||||
|
fontFamily: 'DingTalk_JinBuTi_Regular' |
||||
|
} |
||||
|
}, |
||||
|
axisLine: { |
||||
|
show: false, |
||||
|
lineStyle: { |
||||
|
color: '#113D72', |
||||
|
width: '1', |
||||
|
type: 'solid' |
||||
|
} |
||||
|
}, |
||||
|
axisTick: { |
||||
|
show: false |
||||
|
}, |
||||
|
splitLine: { |
||||
|
show: true, |
||||
|
lineStyle: { |
||||
|
color: 'rgba(66, 139, 221, 0.2)', |
||||
|
type: 'solid', |
||||
|
opacity: 1, |
||||
|
width: 1 |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
], |
||||
|
series: [ |
||||
|
{ |
||||
|
name: '借出', |
||||
|
type: 'line', |
||||
|
stack: 'Total', |
||||
|
itemStyle: { |
||||
|
color: '#41A3FF' |
||||
|
}, |
||||
|
lineStyle: { |
||||
|
width: 3, |
||||
|
color: '#41A3FF' |
||||
|
}, |
||||
|
showSymbol: false, |
||||
|
areaStyle: { |
||||
|
opacity: 0.6, |
||||
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
||||
|
{ |
||||
|
offset: 0, |
||||
|
color: 'rgba(254, 128, 66, 0)' |
||||
|
}, |
||||
|
{ |
||||
|
offset: 1, |
||||
|
color: '#41A3FF' |
||||
|
} |
||||
|
]) |
||||
|
}, |
||||
|
data: borrowedVals |
||||
|
}, |
||||
|
{ |
||||
|
name: '归还', |
||||
|
type: 'line', |
||||
|
stack: 'Total', |
||||
|
lineStyle: { |
||||
|
width: 3, |
||||
|
color: '#FFD14F' |
||||
|
}, |
||||
|
showSymbol: false, |
||||
|
itemStyle: { |
||||
|
color: '#FFD14F' |
||||
|
}, |
||||
|
areaStyle: { |
||||
|
opacity: 0.6, |
||||
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
||||
|
{ |
||||
|
offset: 0, |
||||
|
color: 'rgba(24, 176, 143, 0)' |
||||
|
}, |
||||
|
{ |
||||
|
offset: 1, |
||||
|
color: '#FFD14F' |
||||
|
} |
||||
|
]) |
||||
|
}, |
||||
|
data: returnVals |
||||
|
} |
||||
|
] |
||||
|
}) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue