Browse Source

总借阅根据接口返回得来展示

master
xuhuajiao 9 months ago
parent
commit
191de5bd0b
  1. 334
      src/components/echart/lineChart.vue

334
src/components/echart/lineChart.vue

@ -1,165 +1,169 @@
<template>
<div id="main" :style="{height:height,width:width}" />
</template>
<script>
import echarts from 'echarts'
import resize from '@/utils/resizeMixins.js'
export default {
name: 'AcrossEcharts',
mixins: [resize],
props: {
chartData: {
type: Object,
require: true,
default: function() {
return {}
}
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '100%'
}
},
data() {
return {
chart: null
}
},
watch: {
'chartData': {
handler(val) {
setTimeout(() => {
this.drawChart()
}, 100)
},
immediate: true,
deep: true
}
},
mounted() {
this.drawChart()
window.addEventListener('resize', this.__resizeHandler)
},
methods: {
drawChart() {
const chartDom = document.getElementById('main')
this.chart = echarts.init(chartDom)
let option = null
option = {
grid: { //
left: '2%',
right: '2%',
bottom: '5%',
top: '8%',
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#339cff'
}
}
},
xAxis: {
type: 'category',
data: this.chartData.totalLendMonth,
axisLine: { // 线
lineStyle: {
color: 'rgba(17, 61, 114,0.5)'
}
},
axisTick: { show: false },
axisLabel: { // x
show: true,
textStyle: {
color: '#fff'
}
}
},
yAxis: {
type: 'value',
min: 5000,
max: 25000,
splitNumber: 5,
axisLine: {
show: false
},
axisLabel: { // x
show: true,
textStyle: {
color: '#fff'
}
},
axisTick: { // 线
show: false
},
splitLine: { // 线
lineStyle: {
color: 'rgba(17, 61, 114,0.5)',
type: 'solid'
}
}
},
series: [
{
name: '借阅量',
data: this.chartData.totalLendData,
type: 'line',
areaStyle: {
normal: {
color: {
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0.1,
color: 'rgba(26, 201, 255, 0.5)' // 0%
},
{
offset: 0.5,
color: 'rgba(26, 201, 255, 0.3)' // 0%
},
{
offset: 0.7,
color: 'rgba(26, 201, 255, 0.2)' // 0%
},
{
offset: 0.9,
color: 'rgba(26, 201, 255, 0.1)' // 100%
}
]
}
}
},
itemStyle: {
normal: {
color: '#339CFF', // 线
lineStyle: {
color: 'rgba(26, 201, 255,0.5)' // 线
}
}
}
}
]
}
option && this.chart.setOption(option)
}
}
}
</script>
<style lang="scss" scoped>
.h{
color: rgb(26, 201, 255);
}
</style>
<template>
<div id="main" :style="{height:height,width:width}" />
</template>
<script>
import echarts from 'echarts'
import resize from '@/utils/resizeMixins.js'
export default {
name: 'AcrossEcharts',
mixins: [resize],
props: {
chartData: {
type: Object,
require: true,
default: function() {
return {}
}
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '100%'
}
},
data() {
return {
chart: null
}
},
watch: {
'chartData': {
handler(val) {
setTimeout(() => {
this.drawChart()
}, 100)
},
immediate: true,
deep: true
}
},
mounted() {
this.drawChart()
window.addEventListener('resize', this.__resizeHandler)
},
methods: {
drawChart() {
const chartDom = document.getElementById('main')
this.chart = echarts.init(chartDom)
let option = null
option = {
grid: { //
left: '2%',
right: '2%',
bottom: '5%',
top: '8%',
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#339cff'
}
}
},
xAxis: {
type: 'category',
data: this.chartData.totalLendMonth,
axisLine: { // 线
lineStyle: {
color: 'rgba(17, 61, 114,0.5)'
}
},
axisTick: { show: false },
axisLabel: { // x
show: true,
textStyle: {
color: '#fff'
}
}
},
yAxis: {
type: 'value',
// min: 5000,
// max: 25000,
min: 0,
max: function(value) {
return Math.ceil(value.max + (value.max - value.min) * 0.2)
},
splitNumber: 5,
axisLine: {
show: false
},
axisLabel: { // x
show: true,
textStyle: {
color: '#fff'
}
},
axisTick: { // 线
show: false
},
splitLine: { // 线
lineStyle: {
color: 'rgba(17, 61, 114,0.5)',
type: 'solid'
}
}
},
series: [
{
name: '借阅量',
data: this.chartData.totalLendData,
type: 'line',
areaStyle: {
normal: {
color: {
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0.1,
color: 'rgba(26, 201, 255, 0.5)' // 0%
},
{
offset: 0.5,
color: 'rgba(26, 201, 255, 0.3)' // 0%
},
{
offset: 0.7,
color: 'rgba(26, 201, 255, 0.2)' // 0%
},
{
offset: 0.9,
color: 'rgba(26, 201, 255, 0.1)' // 100%
}
]
}
}
},
itemStyle: {
normal: {
color: '#339CFF', // 线
lineStyle: {
color: 'rgba(26, 201, 255,0.5)' // 线
}
}
}
}
]
}
option && this.chart.setOption(option)
}
}
}
</script>
<style lang="scss" scoped>
.h{
color: rgb(26, 201, 255);
}
</style>
Loading…
Cancel
Save