1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <template>
- <div>
- <div v-if="flag" :ref="id" class="charts-div" />
- </div>
- </template>
- <script>
- import Vue from 'vue';
- import Component from 'vue-class-component';
- import * as echarts from 'echarts';
- @Component({
- props: {
- id: {
- type: String,
- default: 'myChart',
- },
- data: {
- type: Object,
- default: null,
- },
- s: {
- type: String,
- default: '',
- },
- },
- computed: {
- result() {
- const ca = JSON.parse(JSON.stringify(this.data));
- return ca;
- },
- },
- watch: {
- result() {
- this.drawLine();
- console.log('111111111', this.data);
- },
- },
- })
- export default class Echarts extends Vue {
- flag = true;
- myChart = null;
- created() {
-
-
-
-
-
- this.$nextTick(() => {
- if (!this.myChart) {
- if (this.s) {
- this.myChart = echarts.init(this.$refs[this.id], this.s);
- } else {
- this.myChart = echarts.init(this.$refs[this.id]);
- }
- this.$emit('onload', this.myChart);
- }
- this.drawLine();
- });
- }
- drawLine() {
- if (this.data && this.myChart) {
-
- this.myChart.setOption(this.data);
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .charts-div {
- width: 100%;
- height: 100%;
- }
- </style>
|