ECharts自适应窗体大小

<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <style>
           html,body,#echarts{
           margin:0px;
           padding:0px;
           heigt:100%;
           width:100%;
           }
    </style>
</head>
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div id="echarts" style="height:139px"></div>
    <!-- ECharts单文件引入 -->
     <script src="echarts.js"></script>

    <script type="text/javascript">

    var worldMapContainer = document.getElementById('echarts');

         var resizeWorldMapContainer = function () {
             worldMapContainer.style.width = window.innerWidth+'px';
             worldMapContainer.style.height = window.innerHeight+'px';
         };
         resizeWorldMapContainer();

         // 基于准备好的dom,初始化echarts实例
         var myChart = echarts.init(worldMapContainer);

                var option = {
                 xAxis: {
                show: true,
                   // axisLabel: 45,
                    splitLine:{show: false},//去除网格线
                    type: 'category',
                    axisLabel:{
                        textStyle:{
                           color: '#c9c9ca'
                        }
                    },
                    data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月','8月', '9月', '10月', '11月', '12月']
                },
                yAxis: {
                    splitLine:{show: true},//去除网格线
                    type: 'value',
                    axisLabel:{
                        textStyle:{
                           color: '#c9c9ca'
                        }
                    },
                },
                series: [{
                barWidth : 18,//柱图宽度
                itemStyle:{
                normal:{
                 color:'#65ffff',
                 }
                  },
                    data: [120, 200, 150, 80, 70, 110, 130, 200, 300, 400, 500, 120],
                    type: 'bar'
                }]
            };

// 为echarts对象加载数据
myChart.setOption(option);
//窗体自适应
window.onresize = function () {
    resizeWorldMapContainer();
    myChart.resize();
};

        </script>
</body>
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值