Commit 24b85236 by chenwq

折线图

1 parent 7cf5c116
......@@ -17,10 +17,6 @@ export default {
name: 'LineChart',
props: {
// height: {
// type: String,
// default: '19.8vh'
// },
apiName: {
type: String,
default: ''
......@@ -46,15 +42,18 @@ export default {
dataIndex: -1
},
timer: null
// chartHeight: this.height
}
},
created() {
this.lineOptions = getLineOptions({ axisLabelColor: this.axisLabelColor })
this.lineOptions = getLineOptions({ tooltipFormatter: this.tooltipFormatter })
},
mounted() {
this.lineDom = document.getElementById('line-chart')
this.echartsLine = echarts.init(this.lineDom)
this.chartBindEvent()
this.drawLine()
},
......@@ -63,26 +62,43 @@ export default {
this.lineOptions.xAxis.data = this.xAxisLabel.monthList
},
tooltipFormatter(obj) {
var currentItem = this.dataList[obj[0].dataIndex]
return `数量:${currentItem}<br>环比:${currentItem}<br>同比:${currentItem}`
},
autoMove() {
clearTimeout(this.timer)
this.timer = setTimeout(() => {
clearInterval(this.timer)
this.timer = setInterval(() => {
this.moveAttr.dataIndex = this.moveAttr.dataIndex + 1
if (this.moveAttr.dataIndex === this.dataList.length) {
this.moveAttr.dataIndex = 0
}
this.moveAction()
this.chartAction()
this.autoMove()
}, this.moveAttr.speed)
},
chartBindEvent() {
this.echartsLine.on('click', () => {
// clearTimeout(this.timer)
console.log('???????')
// resize
window.addEventListener('resize', () => {
this.echartsLine.resize()
})
// 鼠标划入
this.lineDom.addEventListener('mouseover', () => {
clearInterval(this.timer)
this.chartAction('downplay')
})
// 鼠标划出
this.lineDom.addEventListener('mouseout', () => {
this.moveAttr.dataIndex = -1
this.autoMove()
})
},
moveAction(type) {
chartAction(type) {
this.echartsLine.dispatchAction({
type: type || 'showTip',
seriesIndex: this.moveAttr.seriesIndex,
......@@ -91,22 +107,18 @@ export default {
},
drawLine() {
// var lineDom = document.getElementById('line-chart')
// this.echartsLine = echarts.init(lineDom)
this.echartsLine = echarts.init(document.getElementById('line-chart'))
this.dealxAxisLabel()
this.lineOptions.series[0].data = this.dataList
this.echartsLine.setOption(this.lineOptions)
console.log(this.echartsLine)
this.chartBindEvent()
// this.autoMove()
this.autoMove()
},
handleRankChange(value) {
this.rankFlag = value
this.$emit('handleRankChange', value)
}
}
}
......
function getLineOptions(obj) {
// const { axisLabelColor } = obj
const { tooltipFormatter } = obj
console.log(obj)
var lineOptions = {
tooltip: {
trigger: 'axis',
formatter: ''
borderWidth: 0,
backgroundColor: 'rgba(68,68,68,0.80)',
textStyle: {
color: '#FFFFFF',
fontSize: '8px'
},
extraCssText: 'width: 60px;',
formatter: tooltipFormatter || ''
},
grid: {
left: '3%',
......@@ -17,7 +24,6 @@ function getLineOptions(obj) {
type: 'category',
axisLabel: {
color: '#606266',
// color: axisLabelColor ? (value, index) => axisLabelColor(value, index) : '#606266',
fontSize: '0.8em'
},
data: []
......
......@@ -8,7 +8,7 @@
<template>
<div>
<div class="title">售后档案客户</div>
<LineChart :height="height"></LineChart>
<LineChart @handleRankChange="handleRankChange"></LineChart>
</div>
</template>
......@@ -20,6 +20,12 @@ export default {
type: String,
default: '19.8vh'
}
},
mounted() { },
methods: {
handleRankChange(value) {
console.log(value)
}
}
}
</script>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!