123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <template>
- <div class="ChartsLine" :id="id"></div>
- </template>
- <script>
- import ChartsLine from '../../mixin/commonChartsLine'
- export default {
- name: 'ChartsLine',
- props: {
-
- id: {
- type: String,
- default: ''
- },
-
- option: {
- type: Object,
- default: () => { }
- }
- },
- mixins: [ChartsLine],
- data () {
- return {
- myChart: null,
- desc: 300
- }
- },
- mounted () {
-
- this.initEcharts()
-
- window.addEventListener('resize', _.debounce(this.handle, this.desc))
- },
- beforeDestroy () {
-
- if (this.myChart) {
- this.myChart.dispose()
- window.removeEventListener('resize', this.handle)
- this.myChart = null
- }
- },
- watch: {
-
- option: {
- handler (obj) {
-
- const objData = _.cloneDeep(this.options)
- _.merge(objData, obj)
-
- this.myChart.setOption(objData)
- },
- deep: true
- }
- },
- methods: {
-
- handle () {
- if (this.myChart) {
- this.myChart.resize()
- }
- },
-
- initEcharts () {
-
- const objData = _.cloneDeep(this.options)
- _.merge(objData, this.option)
-
- const chartDom = document.getElementById(this.id)
-
- this.myChart = this.$echarts.init(chartDom)
-
- this.myChart.setOption(objData)
-
- this.myChart.on('click', params => {
- this.$emit('getChartData', params)
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .ChartsLine {
- height: 100%;
- width: 100%;
- position: absolute;
- left: 0;
- top: 0;
- }
- </style>
|