• vue echart统计图自适应屏幕大小变化


    <template>
    <div class="about">
        <h1>This is an about page</h1>
    
        <el-row>
            <el-col :span="24">
                <div id="pie"></div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <div id="pie2"></div>
            </el-col>
        </el-row>
    </div>
    </template>
    
    <script>
    // 引入 ECharts 主模块
    var echarts = require('echarts/lib/echarts');
    // 引入柱状图
    require('echarts/lib/chart/bar');
    // 引入提示框和标题组件
    require('echarts/lib/component/tooltip');
    require('echarts/lib/component/title');
    
    export default {
        name: "about",
        data() {
            return {
                // clientHeight: '600px',
                screenWidth: document.body.clientWidth,
                myChart: null,
                myChart2:null
            }
        },
        mounted() {
            console.log('mouted')
            // 基于准备好的dom,初始化echarts实例
        console.log(this.screenWidth)
            const that = this
            window.onresize = () => {
                return (() => {
                    window.screenWidth = document.body.clientWidth
                    that.screenWidth = window.screenWidth
                })()
            }
    
            that.drawPie();
            that.drawPie2();
        },
        watch: {
            screenWidth(val) {
                this.screenWidth = val
                console.log(this.screenWidth)
                console.log(screenWidth);
                // this.drawPie();
                // this.drawPie2();
    
                this.myChart.resize();
                this.myChart2.resize();
            }
        },
        methods: {
            drawPie: function () {
                this.myChart = echarts.init(document.getElementById('pie'));
                // 绘制图表
                var option = {
                    title: {
                        text: 'ECharts 入门示例'
                    },
                    tooltip: {},
                    xAxis: {
                        data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
                    },
                    yAxis: {},
                    series: [{
                        name: '销量',
                        type: 'bar',
                        data: [5, 20, 36, 10, 10, 20]
                    }]
                }
                this.myChart.setOption(option);
                // setTimeout(() => {
                //     window.onresize = this.myChart.resize
                //     alert('1')
                // }, 200)
    
            }
            ,drawPie2: function () {
                this.myChart2 = echarts.init(document.getElementById('pie2'));
                // 绘制图表
                var option = {
                    title: {
                        text: 'ECharts 入门示例'
                    },
                    tooltip: {},
                    xAxis: {
                        data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
                    },
                    yAxis: {},
                    series: [{
                        name: '销量',
                        type: 'bar',
                        data: [5, 20, 36, 10, 10, 20]
                    }]
                }
                this.myChart2.setOption(option);
                // setTimeout(() => {
                //     window.onresize = this.myChart2.resize
                // }, 200)
    
            }
    
    
        }
    
    }
    </script>
    
    <style>
    #pie,#pie2 {
         100%;
        height: 400px;
    }
    </style>
    
    微信公众号:jingfeng18 免费学习领取最新的前端学习资源
  • 相关阅读:
    spring-boot:run启动时,如何带设置环境参数dev,test.
    git多人参与的项目 -> 分支代码如何合并到主干
    如何使用IDEA运行 一个分布式的项目
    学习反射 并尝试写一个反射的工具类
    SVN提交大量无效文件补救方法
    IDEA基础配置
    Eclipse常用快捷键与IDEA中的对比.
    如何运行一个分布式的Maven项目
    Java常考面试题整理(六)
    python并发——多进程中的异常捕获
  • 原文地址:https://www.cnblogs.com/qianduanshiping/p/11826863.html
Copyright © 2020-2023  润新知