数据可视化之大屏模板和自适应放大缩小方法

废话不多说直接上根据屏幕视口大小自动缩放的实现方法

方法一

通过js获取窗口宽高进行缩放建议配合vh,vw食用

<script>
    console.log(window.screen)
    let screenWidth = window.screen.width
    let screenHeight = window.screen.height

    let box = document.querySelector('.box')

    box.style.width = screenWidth + 'px'
    box.style.height = screenHeight + 'px'

    // window.innerWidth
    let pageWidth = window.innerWidth

    let scale = pageWidth / screenWidth

    document.body.style.transform = `scale(${scale})`


    window.onresize = function () {
      let pageWidth = window.innerWidth
      let scale = pageWidth / screenWidth

      document.body.style.transform = `scale(${scale})`

    }
  </script>

然后里面的echarts图表通过监听窗口变化实现自适应

pieChart1为你初始化的图表

window.onresize = function () {
        pieChart1.resize();
      };

效果图

 模板代码

css

 body {
        margin: 0;
      }

      .box {
        background: url(./img/bg.png) center center / cover;
        transform-origin: left top;
        position: relative;
      }

      .header {
        height: 80px;
      }

      .header h2 {
        text-align: center;
        color: #fff;
        font-size: 30px;
        font-weight: normal;
        margin: 0;
        line-height: 80px;
      }

      .main {
        height: calc(100vh - 80px);

        position: relative;
        /* top: 80px; */
        left: 0;
        bottom: 0;
        right: 0;
        display: flex;
      }

      .lt {
        position: absolute;
        left: 0;
        top: 0;
      }

      .rt {
        position: absolute;
        right: 0;
        top: 0;
        transform: rotateY(180deg);
      }

      .lb {
        position: absolute;
        bottom: 0;
        left: 0;
        transform: rotateX(180deg);
      }

      .rb {
        position: absolute;
        bottom: 0;
        right: 0;
        transform: rotateX(180deg) rotateY(180deg);
      }

      .left-container {
        width: 22%;
        position: relative;
        border: 5px solid #fff;
        margin: 20px;
      }

      .right-container {
        width: 78%;
        margin: 20px;
        display: flex;
        flex-direction: column;
        margin-left: 0;
      }

      .right-bottom-container {
        height: 35%;
        margin-top: 20px;
        border: 5px solid #fff;
      }

      .right-top-container {
        height: 65%;
        display: flex;
      }

      .right-top-left-container {
        border: 5px solid #fff;
        width: 65%;
        margin-right: 20px;
      }

      .right-top-right-container {
        width: 35%;
        display: flex;
        flex-direction: column;
      }

      .right-top-right-top-container {
        border: 5px solid #fff;
        height: 50%;
        margin-bottom: 10px;
      }

      .right-top-right-bottom-container {
        border: 5px solid #fff;
        height: 50%;
        margin-top: 10px;
      }

      .pie-1 {
        width: 100%;
        height: 30%;
      }
      .pie-2 {
        width: 100%;
        height: 100%;
      }

html

 <div class="box">
      <div class="header">
        <h2>机电设备电子档案</h2>
      </div>
      <div class="main">
        <svg class="lt" width="150" height="150">
          <polygon
            fill="#4fd2dd"
            points="6,66 6,18 12,12 18,12 24,6 27,6 30,9 36,9 39,6 84,6 81,9 75,9 73.2,7 40.8,7 37.8,10.2 24,10.2 12,21 12,24 9,27 9,51 7.8,54 7.8,63"
          >
            <animate
              attributeName="fill"
              values="#4fd2dd;#235fa7;#4fd2dd"
              dur="0.5s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
          <polygon
            fill="#235fa7"
            points="27.599999999999998,4.8 38.4,4.8 35.4,7.8 30.599999999999998,7.8"
          >
            <animate
              attributeName="fill"
              values="#235fa7;#4fd2dd;#235fa7"
              dur="0.5s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
          <polygon
            fill="#4fd2dd"
            points="9,54 9,63 7.199999999999999,66 7.199999999999999,75 7.8,78 7.8,110 8.4,110 8.4,66 9.6,66 9.6,54"
          >
            <animate
              attributeName="fill"
              values="#4fd2dd;#235fa7;transparent"
              dur="1s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
        </svg>
        <svg class="rt" width="150" height="150">
          <polygon
            fill="#4fd2dd"
            points="6,66 6,18 12,12 18,12 24,6 27,6 30,9 36,9 39,6 84,6 81,9 75,9 73.2,7 40.8,7 37.8,10.2 24,10.2 12,21 12,24 9,27 9,51 7.8,54 7.8,63"
          >
            <animate
              attributeName="fill"
              values="#4fd2dd;#235fa7;#4fd2dd"
              dur="0.5s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
          <polygon
            fill="#235fa7"
            points="27.599999999999998,4.8 38.4,4.8 35.4,7.8 30.599999999999998,7.8"
          >
            <animate
              attributeName="fill"
              values="#235fa7;#4fd2dd;#235fa7"
              dur="0.5s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
          <polygon
            fill="#4fd2dd"
            points="9,54 9,63 7.199999999999999,66 7.199999999999999,75 7.8,78 7.8,110 8.4,110 8.4,66 9.6,66 9.6,54"
          >
            <animate
              attributeName="fill"
              values="#4fd2dd;#235fa7;transparent"
              dur="1s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
        </svg>
        <svg class="rb" width="150" height="150">
          <polygon
            fill="#4fd2dd"
            points="6,66 6,18 12,12 18,12 24,6 27,6 30,9 36,9 39,6 84,6 81,9 75,9 73.2,7 40.8,7 37.8,10.2 24,10.2 12,21 12,24 9,27 9,51 7.8,54 7.8,63"
          >
            <animate
              attributeName="fill"
              values="#4fd2dd;#235fa7;#4fd2dd"
              dur="0.5s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
          <polygon
            fill="#235fa7"
            points="27.599999999999998,4.8 38.4,4.8 35.4,7.8 30.599999999999998,7.8"
          >
            <animate
              attributeName="fill"
              values="#235fa7;#4fd2dd;#235fa7"
              dur="0.5s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
          <polygon
            fill="#4fd2dd"
            points="9,54 9,63 7.199999999999999,66 7.199999999999999,75 7.8,78 7.8,110 8.4,110 8.4,66 9.6,66 9.6,54"
          >
            <animate
              attributeName="fill"
              values="#4fd2dd;#235fa7;transparent"
              dur="1s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
        </svg>
        <svg class="lb" width="150" height="150">
          <polygon
            fill="#4fd2dd"
            points="6,66 6,18 12,12 18,12 24,6 27,6 30,9 36,9 39,6 84,6 81,9 75,9 73.2,7 40.8,7 37.8,10.2 24,10.2 12,21 12,24 9,27 9,51 7.8,54 7.8,63"
          >
            <animate
              attributeName="fill"
              values="#4fd2dd;#235fa7;#4fd2dd"
              dur="0.5s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
          <polygon
            fill="#235fa7"
            points="27.599999999999998,4.8 38.4,4.8 35.4,7.8 30.599999999999998,7.8"
          >
            <animate
              attributeName="fill"
              values="#235fa7;#4fd2dd;#235fa7"
              dur="0.5s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
          <polygon
            fill="#4fd2dd"
            points="9,54 9,63 7.199999999999999,66 7.199999999999999,75 7.8,78 7.8,110 8.4,110 8.4,66 9.6,66 9.6,54"
          >
            <animate
              attributeName="fill"
              values="#4fd2dd;#235fa7;transparent"
              dur="1s"
              begin="0s"
              repeatCount="indefinite"
            ></animate>
          </polygon>
        </svg>

        <div class="left-container">
          <div class="pie-1"></div>
        </div>
        <div class="right-container">
          <div class="right-top-container">
            <div class="right-top-left-container">
              <div class="pie-2"></div>
            </div>
            <div class="right-top-right-container">
              <div class="right-top-right-top-container"></div>
              <div class="right-top-right-bottom-container"></div>
            </div>
          </div>
          <div class="right-bottom-container"></div>
        </div>
      </div>
    </div>

js

      // 第一个饼图
      let pieChart1 = echarts.init(document.querySelector(".pie-1"));
      let pieChart1Option = {
        color: ["#469f4b", "#00baff", "#3de7c9", "#ffffff", "#ffc530"],
        tooltip: {
          trigger: "item",
        },

        series: [
          {
            type: "pie",
            label: {
              color: "#fff",
              formatter: "{d}%\n{b}",
            },
            tooltip: {
              show: false,
            },
            emphasis: {
              disabled: true,
            },
            radius: ["30%", "40%"],
            data: [
              { value: 1048, name: "其他" },
              { value: 735, name: "收费系统" },
              { value: 580, name: "通信系统" },
              { value: 484, name: "监控系统" },
              { value: 300, name: "供配电系统" },
            ],
          },
        ],
      };
      pieChart1.setOption(pieChart1Option);
      window.onresize = function () {
        pieChart1.resize();
      };

bg图

相信到了这里剩下的图表数据啊排版啥的就不用我多说了吧,直接按部就班开发就好,有收获就点个关注吧

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

csdn文章推荐受影响解决办法10个字10行

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

object not found

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值