|
|
@ -1,70 +1,70 @@ |
|
|
|
<template> |
|
|
|
<div class="screenEchartsFrame" |
|
|
|
ref="screenEchartsFrame"></div> |
|
|
|
<div class="screenEchartsFrame" ref="screenEchartsFrame"></div> |
|
|
|
</template> |
|
|
|
|
|
|
|
<script> |
|
|
|
import * as echarts from 'echarts'; |
|
|
|
export default { |
|
|
|
name: 'screen-echarts-frame', |
|
|
|
data () { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
myChart: '' |
|
|
|
} |
|
|
|
}; |
|
|
|
}, |
|
|
|
props: { |
|
|
|
chartMethod: { |
|
|
|
type: Function |
|
|
|
} |
|
|
|
}, |
|
|
|
mounted () { |
|
|
|
this.initChart() |
|
|
|
mounted() { |
|
|
|
this.initChart(); |
|
|
|
window.onresize = () => { |
|
|
|
this.myChart.resize() |
|
|
|
} |
|
|
|
this.myChart.resize(); |
|
|
|
}; |
|
|
|
}, |
|
|
|
beforeDestroy () { |
|
|
|
beforeDestroy() { |
|
|
|
// 销毁echarts实例对象 |
|
|
|
if (this.myChart) this.myChart.dispose() |
|
|
|
if (this.myChart) this.myChart.dispose(); |
|
|
|
}, |
|
|
|
watch: {}, |
|
|
|
methods: { |
|
|
|
initChart () { |
|
|
|
initChart() { |
|
|
|
this.$nextTick(() => { |
|
|
|
const dom = this.$refs.screenEchartsFrame |
|
|
|
this.myChart = echarts.init(dom) |
|
|
|
const dom = this.$refs.screenEchartsFrame; |
|
|
|
this.myChart = echarts.init(dom); |
|
|
|
// this.myChart.setOption(this.chartMethod()) |
|
|
|
this.$emit('myChartMethod', this.myChart) |
|
|
|
}) |
|
|
|
this.$emit('myChartMethod', this.myChart); |
|
|
|
}); |
|
|
|
}, |
|
|
|
// 配置option |
|
|
|
setOption (option) { |
|
|
|
this.myChart.setOption(option) |
|
|
|
let than = this |
|
|
|
this.myChart.on('click',function(param){ |
|
|
|
than.$emit('handelClickMyPei',param) |
|
|
|
}) |
|
|
|
setOption(option) { |
|
|
|
this.myChart.setOption(option); |
|
|
|
let than = this; |
|
|
|
this.myChart.off('click'); |
|
|
|
this.myChart.on('click', function(param) { |
|
|
|
than.$emit('handelClickMyPei', param); |
|
|
|
}); |
|
|
|
}, |
|
|
|
// 获取option |
|
|
|
getOption () { |
|
|
|
getOption() { |
|
|
|
if (this.myChart) { |
|
|
|
return this.myChart.getOption() |
|
|
|
return this.myChart.getOption(); |
|
|
|
} else { |
|
|
|
return null |
|
|
|
return null; |
|
|
|
} |
|
|
|
}, |
|
|
|
// |
|
|
|
resize () { |
|
|
|
resize() { |
|
|
|
if (this.myChart) { |
|
|
|
this.myChart.resize() |
|
|
|
this.myChart.resize(); |
|
|
|
} |
|
|
|
}, |
|
|
|
clear () { |
|
|
|
clear() { |
|
|
|
if (this.myChart) { |
|
|
|
this.myChart.clear() |
|
|
|
this.myChart.clear(); |
|
|
|
} |
|
|
|
}, |
|
|
|
showLoading () { |
|
|
|
showLoading() { |
|
|
|
if (this.myChart) { |
|
|
|
this.$nextTick(() => { |
|
|
|
this.myChart.showLoading({ |
|
|
@ -73,86 +73,86 @@ export default { |
|
|
|
textColor: '#29cdff', |
|
|
|
maskColor: 'rgba(255, 255, 255, 0)', |
|
|
|
zlevel: 0 |
|
|
|
}) |
|
|
|
}) |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
hideLoading () { |
|
|
|
hideLoading() { |
|
|
|
if (this.myChart) { |
|
|
|
this.myChart.hideLoading() |
|
|
|
this.myChart.hideLoading(); |
|
|
|
} |
|
|
|
}, |
|
|
|
// 启动动画时使用 |
|
|
|
tooltipAnimate (chart, length) { |
|
|
|
tooltipAnimate(chart, length) { |
|
|
|
// 清除上一次动画 |
|
|
|
this.timeTicket && clearInterval(this.timeTicket) |
|
|
|
const count = 0 |
|
|
|
this.timeTicket && clearInterval(this.timeTicket); |
|
|
|
const count = 0; |
|
|
|
// 启动动画 |
|
|
|
this._action(chart, count, length) |
|
|
|
this._action(chart, count, length); |
|
|
|
chart && // 移除动画 |
|
|
|
chart.on('mouseover', params => { |
|
|
|
this._cleanAction(chart, params) |
|
|
|
}) |
|
|
|
this._cleanAction(chart, params); |
|
|
|
}); |
|
|
|
// 重写启动动画 |
|
|
|
chart && |
|
|
|
chart.on('mouseout', () => { |
|
|
|
this._action(chart, count, length) |
|
|
|
}) |
|
|
|
this._action(chart, count, length); |
|
|
|
}); |
|
|
|
}, |
|
|
|
// tooltip动画action |
|
|
|
_action (chart, count, length) { |
|
|
|
this.timeTicket && clearInterval(this.timeTicket) |
|
|
|
_action(chart, count, length) { |
|
|
|
this.timeTicket && clearInterval(this.timeTicket); |
|
|
|
this.timeTicket = setInterval(() => { |
|
|
|
if (!chart) { |
|
|
|
clearInterval(this.timeTicket) |
|
|
|
return |
|
|
|
clearInterval(this.timeTicket); |
|
|
|
return; |
|
|
|
} |
|
|
|
chart && |
|
|
|
chart.dispatchAction({ |
|
|
|
type: 'downplay', |
|
|
|
seriesIndex: 0 |
|
|
|
}) |
|
|
|
}); |
|
|
|
chart && |
|
|
|
chart.dispatchAction({ |
|
|
|
type: 'highlight', |
|
|
|
seriesIndex: 0, |
|
|
|
dataIndex: count % length |
|
|
|
}) |
|
|
|
}); |
|
|
|
chart && |
|
|
|
chart.dispatchAction({ |
|
|
|
type: 'showTip', |
|
|
|
seriesIndex: 0, |
|
|
|
dataIndex: count % length |
|
|
|
}) |
|
|
|
count++ |
|
|
|
}, 1000 * 3) |
|
|
|
}); |
|
|
|
count++; |
|
|
|
}, 1000 * 3); |
|
|
|
}, |
|
|
|
_cleanAction (chart, params) { |
|
|
|
this.timeTicket && clearInterval(this.timeTicket) |
|
|
|
_cleanAction(chart, params) { |
|
|
|
this.timeTicket && clearInterval(this.timeTicket); |
|
|
|
if (!chart) { |
|
|
|
clearInterval(this.timeTicket) |
|
|
|
return |
|
|
|
clearInterval(this.timeTicket); |
|
|
|
return; |
|
|
|
} |
|
|
|
chart && |
|
|
|
chart.dispatchAction({ |
|
|
|
type: 'downplay', |
|
|
|
seriesIndex: 0 |
|
|
|
}) |
|
|
|
}); |
|
|
|
chart && |
|
|
|
chart.dispatchAction({ |
|
|
|
type: 'highlight', |
|
|
|
seriesIndex: 0, |
|
|
|
dataIndex: params.dataIndex |
|
|
|
}) |
|
|
|
}); |
|
|
|
chart && |
|
|
|
chart.dispatchAction({ |
|
|
|
type: 'showTip', |
|
|
|
seriesIndex: 0, |
|
|
|
dataIndex: params.dataIndex |
|
|
|
}) |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
</script> |
|
|
|
|
|
|
|
<style lang="scss" scoped> |
|
|
|