Commit 24b85236 by chenwq

折线图

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