12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <template>
- <div :class="className" :style="{height:height,width:width}" />
- </template>
- <script>
- // NOTE: hht 22.1.27 改造成通用组件
- // https://echarts.apache.org/examples/zh/
- import echarts from 'echarts'
- require('echarts/theme/macarons') // echarts theme
- import resize from './mixins/resize'
- export default {
- name: 'mx-chart',
- mixins: [resize],
- props: {
- className: {
- type: String,
- default: 'chart'
- },
- width: {
- type: String,
- default: '100%'
- },
- height: {
- type: String,
- default: '300px'
- },
- options: {
- type: Object,
- default: null
- }
- },
- data() {
- return {
- chart: null
- }
- },
- watch: {
- options: function(opt) {
- if (!this.chart || !opt) return
- console.log('mx-chart set option', this.options)
- this.chart.setOption(opt, true) // true: notMerge
- }
- },
- mounted() {
- this.$nextTick(() => {
- this.initChart()
- })
- },
- beforeDestroy() {
- if (!this.chart) {
- return
- }
- this.chart.dispose()
- this.chart = null
- },
- methods: {
- initChart() {
- this.chart = echarts.init(this.$el, 'macarons')
- if (!this.options) return
- console.log('mx-chart set option', this.options)
- this.chart.setOption(this.options)
- }
- }
- }
- </script>
- <style scoped>
- </style>
|