|
|
@ -1,6 +1,6 @@ |
|
|
|
<template> |
|
|
|
<!-- 近七日借阅统计 --> |
|
|
|
<div id="main1" :style="{height:height,width:width}" /> |
|
|
|
<div id="main1" ref="chartContainer" :style="{height:height,width:width}" /> |
|
|
|
</template> |
|
|
|
|
|
|
|
<script> |
|
|
@ -34,18 +34,27 @@ export default { |
|
|
|
} |
|
|
|
}, |
|
|
|
watch: { |
|
|
|
'chartWeeklyData': { |
|
|
|
chartWeeklyData: { |
|
|
|
handler(val) { |
|
|
|
setTimeout(() => { |
|
|
|
this.drawChart() |
|
|
|
this.initChart() |
|
|
|
}, 100) |
|
|
|
}, |
|
|
|
immediate: true, |
|
|
|
deep: true |
|
|
|
} |
|
|
|
}, |
|
|
|
beforeDestroy() { |
|
|
|
if (!this.chart) { |
|
|
|
return |
|
|
|
} |
|
|
|
this.chart.dispose() |
|
|
|
this.chart = null |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
this.drawChart() |
|
|
|
this.$nextTick(() => { |
|
|
|
this.initChart() |
|
|
|
}) |
|
|
|
this.resetPieChartData() |
|
|
|
}, |
|
|
|
methods: { |
|
|
@ -59,100 +68,16 @@ export default { |
|
|
|
} |
|
|
|
// 不先清空chart没法重绘 |
|
|
|
this.chart.clear() |
|
|
|
this.chart.setOption(this.option) // 获取echarts数据的方法 |
|
|
|
this.initChart() |
|
|
|
}, 8000) |
|
|
|
}, |
|
|
|
drawChart() { |
|
|
|
const app = {} |
|
|
|
const chartDom = document.getElementById('main1') |
|
|
|
this.chart = echarts.init(chartDom) |
|
|
|
|
|
|
|
let option = null |
|
|
|
const posList = [ |
|
|
|
'left', |
|
|
|
'right', |
|
|
|
'top', |
|
|
|
'bottom', |
|
|
|
'inside', |
|
|
|
'insideTop', |
|
|
|
'insideLeft', |
|
|
|
'insideRight', |
|
|
|
'insideBottom', |
|
|
|
'insideTopLeft', |
|
|
|
'insideTopRight', |
|
|
|
'insideBottomLeft', |
|
|
|
'insideBottomRight' |
|
|
|
] |
|
|
|
app.configParameters = { |
|
|
|
rotate: { |
|
|
|
min: -90, |
|
|
|
max: 90 |
|
|
|
}, |
|
|
|
align: { |
|
|
|
options: { |
|
|
|
left: 'left', |
|
|
|
center: 'center', |
|
|
|
right: 'right' |
|
|
|
} |
|
|
|
initChart() { |
|
|
|
// const dom = document.getElementById('main2') |
|
|
|
const dom = this.$refs.chartContainer |
|
|
|
this.chart = echarts.init(dom) |
|
|
|
this.setOptions(this.chartWeeklyData) |
|
|
|
}, |
|
|
|
verticalAlign: { |
|
|
|
options: { |
|
|
|
top: 'top', |
|
|
|
middle: 'middle', |
|
|
|
bottom: 'bottom' |
|
|
|
} |
|
|
|
}, |
|
|
|
position: { |
|
|
|
options: posList.reduce(function(map, pos) { |
|
|
|
map[pos] = pos |
|
|
|
return map |
|
|
|
}, {}) |
|
|
|
}, |
|
|
|
distance: { |
|
|
|
min: 0, |
|
|
|
max: 100 |
|
|
|
} |
|
|
|
} |
|
|
|
app.config = { |
|
|
|
rotate: 90, |
|
|
|
align: 'left', |
|
|
|
verticalAlign: 'middle', |
|
|
|
position: 'insideBottom', |
|
|
|
distance: 15, |
|
|
|
onChange: function() { |
|
|
|
const labelOption = { |
|
|
|
rotate: app.config.rotate, |
|
|
|
align: app.config.align, |
|
|
|
verticalAlign: app.config.verticalAlign, |
|
|
|
position: app.config.position, |
|
|
|
distance: app.config.distance |
|
|
|
} |
|
|
|
this.chart.setOption({ |
|
|
|
series: [ |
|
|
|
{ |
|
|
|
label: labelOption |
|
|
|
}, |
|
|
|
{ |
|
|
|
label: labelOption |
|
|
|
} |
|
|
|
] |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
const labelOption = { |
|
|
|
show: false, |
|
|
|
position: app.config.position, |
|
|
|
distance: app.config.distance, |
|
|
|
align: app.config.align, |
|
|
|
verticalAlign: app.config.verticalAlign, |
|
|
|
rotate: app.config.rotate, |
|
|
|
formatter: '{c} {name|{a}}', |
|
|
|
fontSize: 16, |
|
|
|
rich: { |
|
|
|
name: {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
setOptions({ date, outchartWeeklyData, inchartWeeklyData } = {}) { |
|
|
|
// 获取当前日期 |
|
|
|
var today = new Date() |
|
|
|
// 计算一周前的日期 |
|
|
@ -165,7 +90,7 @@ export default { |
|
|
|
xAxisData.push(echarts.format.formatTime('yyyy-MM-dd', day)) |
|
|
|
} |
|
|
|
|
|
|
|
option = { |
|
|
|
this.chart.setOption({ |
|
|
|
tooltip: { |
|
|
|
trigger: 'axis', |
|
|
|
axisPointer: { |
|
|
@ -211,7 +136,7 @@ export default { |
|
|
|
xAxis: [{ |
|
|
|
type: 'category', |
|
|
|
axisTick: { show: false }, |
|
|
|
data: this.chartWeeklyData.date, |
|
|
|
data: date, |
|
|
|
axisLine: { // 轴线的颜色以及宽度 |
|
|
|
lineStyle: { |
|
|
|
color: '#113D72' |
|
|
@ -273,29 +198,30 @@ export default { |
|
|
|
type: 'bar', |
|
|
|
barWidth: 14, // 柱图宽度 |
|
|
|
barGap: '30%', |
|
|
|
label: labelOption, |
|
|
|
emphasis: { |
|
|
|
focus: 'series' |
|
|
|
}, |
|
|
|
data: this.chartWeeklyData.outchartWeeklyData, |
|
|
|
data: outchartWeeklyData, |
|
|
|
itemStyle: { |
|
|
|
color: '#41A3FF' |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '归还', |
|
|
|
type: 'bar', |
|
|
|
barWidth: 14, // 柱图宽度 |
|
|
|
label: labelOption, |
|
|
|
emphasis: { |
|
|
|
focus: 'series' |
|
|
|
}, |
|
|
|
data: this.chartWeeklyData.inchartWeeklyData, |
|
|
|
color: '#F9BE1D' |
|
|
|
data: inchartWeeklyData, |
|
|
|
itemStyle: { |
|
|
|
color: '#FFD14F' |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
this.option = option |
|
|
|
option && this.chart.setOption(option) |
|
|
|
] |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|