Echarts大屏可视化——布局

3,330 阅读2分钟

知识点

  1. div+css布局
  2. flex布局—》三栏自适应
  3. less
  4. rem适配
  5. 手淘的flexible.js

布局

头部——header

标题+实时时间

主体框——main

三栏布局:

  1. 左边三个图表

  2. 中间一个地图+统计

  3. 右边三个图表

image.png

html布局:

<header>
      <h1>可视化数据</h1>
      <div class="showTime">实时时间</div>
    </header>
    <main>
      <section class="column">
        <div class="panel bar">
         图表一
         <div class="panel-footer"></div>
        </div>
        <div class="panel line">
         图表二
         <div class="panel-footer"></div>
        </div>
        <div class="panel pie">
         图表三
         <div class="panel-footer"></div>
        </div>
      </section>
      <section class="column">
        <div class="no">
         统计
        </div>
        <div class="map">
          地图
        </div>
      </section>
      <section class="column">
        <div class="panel bar2">
         图表一
         <div class="panel-footer"></div>
        </div>
        <div class="panel line2">
         图表二
         <div class="panel-footer"></div>
        </div>
        <div class="panel pie2">
          图表三
          <div class="panel-footer"></div>
        </div>
      </section>
    </main>

less:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  background: url("../images/bg.jpg") no-repeat top center;
}
header {
  position: relative;
  height: 1.25rem;
  background: url("../images/head_bg.png") no-repeat;
  h1 {
    font-size: 0.475rem;
    color: #fff;
    text-align: center;
    line-height: 1.25rem;
  }
  .showTime {
    position: absolute;
    right: 0.375rem;
    top: 0;
    line-height: 0.9375rem;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.25rem;
  }
}

main {
  display: flex;
  min-width: 1024px;
  max-width: 1920px;
  margin: 0 auto;
  padding: 0.125rem 0.125rem 0;
  .column {
    flex: 3;
    &:nth-child(2) {
      flex: 5;
      margin: 0 0.125rem 0.1875rem;
    }
  }
  .panel {
    position: relative;
    height: 3.875rem;
    border: 1px solid rgba(255, 255, 255, 0.17);
    background: url("../images/line\(1\).png") no-repeat
      rgba(255, 255, 255, 0.03);
    padding: 0 0.1875rem 0.5rem;
    margin-bottom: 0.1875rem;
    //上边角
    &::before {
      position: absolute;
      content: "";
      top: 0;
      left: 0;
      width: 10px;
      height: 10px;
      border-left: 2px solid #02a6b5;
      border-top: 2px solid #02a6b5;
    }
    &::after {
      position: absolute;
      content: "";
      top: 0;
      right: 0;
      width: 10px;
      height: 10px;
      border-right: 2px solid #02a6b5;
      border-top: 2px solid #02a6b5;
    }
    // 下边角
    .panel-footer {
      position: absolute;
      bottom: 0;
      right: 0;
      height: 20px;
      width: 100%;
      &::before {
        position: absolute;
        content: "";
        bottom: 0;
        left: 0;
        width: 10px;
        height: 10px;
        border-left: 2px solid #02a6b5;
        border-bottom: 2px solid #02a6b5;
      }
      &::after {
        position: absolute;
        content: "";
        bottom: 0;
        right: 0;
        width: 10px;
        height: 10px;
        border-right: 2px solid #02a6b5;
        border-bottom: 2px solid #02a6b5;
      }
    }
  }
}

.no {
  background-color: rgba(101, 132, 226, 0.1);
  padding: 0.1875rem;
}

.map {
  position: relative;
  height: 10.125rem;
}

结语

  1. flexible 会根据屏幕的宽度大小重新计算根节点html的font-size,1rem = html的font-size,从而实现适配的效果。

  2. 利用flex属性,使三栏布局达到自适应的效果。

  3. 高亮的边角使用绝对定位position:absolute,和伪元素,并为伪元素设置边角实现。