echarts的高度如何动态设置?

 <div id="main" style="width: 100%;height:65vh;margin-top:5vh;position:absolute;"></div>
/*
图表
*/  
        // 基于准备好的dom,初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
 
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '数量top5',
                left:'center',
                top:'10px',
                textStyle: {  //文本样式
                    fontSize: 24,
                    color: '#7f7f7f'
                }

            },
            xAxis: {
                data: ["线路板","电容","电阻","电感","电解"],
                axisTick: {
                  show: false,
                },
                axisLine: { 
                    show: false
                }

            },
            yAxis: [
                {
                type: 'value',
                min: 0, //最小值
                max: 35, //最大值
                interval: 5, //间隔
                axisTick: {
                  show: false,
                },
                axisLine: { 
                    show: false
                }
               }
            ],
            series: [{
                name: '销量',
                type: 'bar',
                data: [32, 19, 18, 15, 12],
                itemStyle: {
                    normal: {
                        color: '#4f81bd',
                        label: {
                                show: true, //显示
                                position: 'top', //在上方
                                textStyle: { //文字样式
                                    color: 'black',
                                    fontSize: 12
                                }
                            }
                    }
                }
            }]
        };
 
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
          
      
        window.onresize = function() { 
            var h1=document.documentElement.clientHeight;//获取屏幕的高度 
            if(h1>700){
              myChart.getDom().style.height = 65 + "vh";
            }else{
              myChart.getDom().style.height = 60 + "vh";
            }
            myChart.resize();        
        }
 
     util.call(function(h){
         //h为点击的那个高度
        var h2=document.documentElement.clientHeight;//获取屏幕的高度 
        console.log(h2);
       if(h2<600){
        //这里重新设置echarts的高度
        myChart.getDom().style.height = ((h2-h)/2)+70 + "px";
        myChart.resize();
       }
      
}) 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值