首页 > 其他分享 >Echarts——VUE中非根节点时不显示图表也无报错

Echarts——VUE中非根节点时不显示图表也无报错

时间:2022-10-31 17:24:38浏览次数:57  
标签:VUE name color data chart options 报错 Echarts echarts

前言

因为之前的封装都是直接作为根节点封装的,使用this.$el,非根组件的时候使用this.$refs.xx指定即可

内容

简写

<div ref="container" :id="id" style="height: 165px; width: 100%"></div>

this.chart = echarts.init(this.$refs.container)

完整示例

<template>
    <div>
        <div
            ref="container"
            :id="id"
            style="height: 165px; width: 100%"></div>
        <div>
            <el-row class="device-info">
                <el-col :span="8">
                    <div class="grid-content">
                        <div class="device-num online">6</div>
                        <div class="info-name">设备总数</div>
                    </div>
                </el-col>
                <el-col :span="8">
                    <div class="grid-content">
                        <div class="device-num online">3</div>
                        <div class="info-name">在线数</div>
                    </div>
                </el-col>
                <el-col :span="8">
                    <div class="grid-content">
                        <div class="device-num off">3</div>
                        <div class="info-name">离线数</div>
                    </div>
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
    name: 'dailyEcharts',
    props: {
        id: {
            type: String,
            default: 'chart',
        },
    },
    data() {
        return {
            chart: null,
            options: {},
            pageflag: false,
            data: [
                { value: 3, name: '在线' },
                { value: 3, name: '离线' },
            ],
        }
    },
    watch: {
        options: {
            handler(options) {
                this.chart.setOption(options, true)
            },
            deep: true,
        },
    },
    created() {
        this.getData()
        this.$nextTick(() => {
            this.initChart()
        })
    },
    beforeDestroy() {
        this.chart.dispose()
        this.chart = null
    },
    methods: {
        getData() {
           .....
        },
        initData() {
            this.options = {
                legend: {
                    top: 'bottom',
                    top: 120,
                    textStyle: { color: '#fff' },
                },
                label: {
                    formatter: '{c}个',
                    color: '#fff',
                },
                color: ['#08E690', '#8FD1D2'],
                series: [
                    {
                        type: 'pie',
                        radius: [10, 45],
                        center: ['50%', '30%'],
                        roseType: 'area',
                        data: this.data,
                    },
                ],
            }
        },
        initChart() {
            this.chart = echarts.init(this.$refs.container)
            this.chart.resize()
            this.chart.clear()
            this.chart.setOption(this.options, true)
        },
    },
}
</script>
<style lang="scss" scoped>
...
</style>

标签:VUE,name,color,data,chart,options,报错,Echarts,echarts
From: https://www.cnblogs.com/wangyang0210/p/16834950.html

相关文章

  • echarts,多比例柱状图渐变色,数据可移动
    varoption={backgroundColor:'#323a5e',tooltip:{trigger:'axis',axisPointer:{//坐标轴指示器,坐标轴触发有效......
  • vue进阶
    1计算属性#如果{{函数()}},每次页面刷新,函数都会重新执行#函数---》当属性来使用,缓存<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8">......
  • 关于vue项目中用户手动刷新,页面回到初始状态的问题
    当点击个人中心后手动刷新页面,下标会回到默认的首页下方此时可以通过vuex+localStorage来解决  在store目录下新建header.js ......
  • vue路由守卫
    路由守卫有三种:1:全局钩子:beforeEach、afterEach2:独享守卫(单个路由里面的钩子):beforeEnter、beforeLeave3:组件内守卫:beforeRouteEnter、beforeRouteUpdate、beforeRout......
  • [Vue]npm创建vue环境
    1.vite创建vue环境[root@PythonVue]#npminitvite@latestNeedtoinstallthefollowingpackages:[email protected]?(y)✔Projectname:…......
  • pycharm 报错表示不支持运行ps1这样的文件
    报错:  解决办法:  管理员的方式打开powershell  Set-ExecutionPolicyRemoteSigned  重启pycharm,,就ok了 ......
  • vue条件渲染
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><metahttp-e......
  • vue防抖
     constdebounce=()=>{axios.get('/api/blog/administration/spot').then(res=>{if(res.data.code==200){}else{this.......
  • vue中间件
    .env.development//部署(文件名).env.production//生产前(文件名)${process.env.VUE_APP_UR}//获取值写一个中间件在写前后台分离的时候肯定是需要发起各种求情......
  • Vue privide 和inject 依赖注入的用法
    from表示在可用的注入内容中搜索用的key,default当然就是默认值。 这里就是我们说的provide,向下提供信息,这里提供的是当前的vue实例,相当于给了后代一个接口。这样在任......