zoukankan      html  css  js  c++  java
  • 大数据可视化 ——从网页前端基础到使用

    大数据可视化【01】——网页前端基础知识(HTML+JAVASCRIPT+CSS)

    ECharts数据可视化项目 中下篇会对教程视频进行文档转录。

    另: 我现在都很讨厌这种纯图/动图/文字 的 学习模式。

    下面两种才能将学习效率提升到最大化好嘛,我也想打造一种这样的学习网站,所以网页基础必须得先打好。

    视频版:

    可交互视频​eater.net图标

    图文版:

    左边文档 右边实战​www.shiyanlou.com图标

     

    【1.HTML】

    建议不要一上来就学HTML,先学会用Typora做笔记,把Typora玩精,等快捷键都记得差不多了(参见下面文章),再去了解HTML标签,什么<b> </b>之类的,typora就一个快捷键的事儿。md标记语言跟html标记语言差不多的,可以进入Source Code Mode 观察,而且Typora也支持导出HTML,可在网页中F12 查看代码。

    X Tesla:学生党/上班族必备软件(不看就后悔!)(Typora最全的快捷键)​zhuanlan.zhihu.com图标
    • a 链接标签,插入标签,href描述链接目标 <a href="https://www.zhihu.com">zhihuya</a>
    • img 图片标签,插入图片<img src="https://www.abcdefg.com/a.jpg" width="100" height="100">
    • <hr>单个hr标签水平分割线
    • <br>单个br标签换行
    • <!-- 注释--> 注释标签
    • CSS修饰
      • 内联样式,即放在h1 p这样的标签内部,<h2 style="">段落呀</h2>
      • 内部样式表,<head><style> ...</style></head>,head换成body也可以。
      • 外部样式表,<body><link rel="stylesheet" href="test.css"></body> ,link定义资源引用地址。
    • div是块级元素,通常以新行来开始,span是内联元素,通常不会以新行开始。

    【2.Javascript】

     

    【3.CSS】

    编辑于 2020-08-11
     

     
    大数据可视化【02】——基础页面分区布局

    大数据可视化【02】——基础页面分区布局

     
    X Tesla:大数据可视化【01】——网页前端基础知识(HTML+JAVASCRIPT+CSS)​zhuanlan.zhihu.com图标ECharts数据可视化项目 视频教程​www.bilibili.comECharts数据可视化项目 实战素材资源包​gitee.com

     

     

    网页新手,如有纰漏,欢迎各路神仙指出。

    一天半哪,全文共6364 words。

    【导图】

     

     

    【Crap】

    先发后补,要不然一天没有个奋斗目标,不写点东西感觉一天好像虚度了一样。

    有时候文字的冲击力没有图片强,图片的冲击力没有视频强,视频的冲击力没有游戏(可交互)强。

    所以做笔记的时候尽量也将目标变成图片,不要是单纯的那种文字,否则会很容易放弃掉你的目标的。

    明确目标和做事的动机比没有方向蛮干更加重要。

    不拖延,今日事,今日毕。

     

    一、可视化适配方案

    2020.8.4

     


    【1.1】配置基础代码

    <html>
     <head>
     <meta charset ="utf-8">
     <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
     </head>
     <body>
     </body>
    </html>

    【01】meta charset 设置网络编码格式

    不同的编码格式进行对比多种网页编码格式

    【02】meta name content 设置屏幕适配设备

    <html>
     <head>
     <meta charset ="utf-8">
     <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
     </head>
     <body>
     </body>
    </html>

    【1.2】初始化CSS

     

    【01】Less 和 Css简介

    准备Less 代码。

    Less其实就是Css的扩展,可以有像javascript那样的变量、函数、嵌套等特性。

    Less.js 中文文档 - Less 中文网​less.bootcss.com图标less和css对比

     

    【02】安装插件Easy LESS

    【03】编写Less代码

    新建 test.less,然后什么都不写,只需要保存一下,就会在同级文件夹中生成一个叫做test.css 的文件。

    index.less: 需要在前面加个小星号,要不然会报错。

    * {
        margin:0;
        padding:0;
        box-sizing:border-box;
    }

    html href 链接引入 同级文件夹css下的index.css文件(less保存会自动编译成css)

    <html>
        <head>
         <meta charset ="utf-8">
         <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <!--  -->
        <link rel="stylesheet" href="css/index.css">    
        </head>
        <body>
        </body>
    </html>

     


    【04】Padding Border Margin相关

    UE UI中的Padding
    UE UI中的Margin

    通过这三个在线实例,我们可以很清晰地了解对比三者Border、Margin、Padding的作用。

    菜鸟教程——Border边框​www.runoob.com菜鸟教程——Margin外边距​www.runoob.com菜鸟教程——Padding填充​www.runoob.com

    【1.3】适配Rem

    【01】加载flexible.js文件

    引入js 文件夹下的flexible.js文件。

    <html>
        <head>
         <meta charset ="utf-8">
         <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
        <link rel="stylesheet" href="css/index.css">    
    </head>
        <body>
           123
            <script src='js/flexible.js'></script>
        </body>
    </html>
    

    flexible.js文件

    var rem =docEl.clientWidth/ 24,24将页面等分成24个片区。

    (function flexible(window, document) {
      var docEl = document.documentElement;
      var dpr = window.devicePixelRatio || 1;
    
      // adjust body font size
      function setBodyFontSize() {
        if (document.body) {
          document.body.style.fontSize = 12 * dpr + "px";
        } else {
          document.addEventListener("DOMContentLoaded", setBodyFontSize);
        }
      }
      setBodyFontSize();
    
      // set 1rem = viewWidth / 10
      function setRemUnit() {
        var rem = docEl.clientWidth / 24;
        docEl.style.fontSize = rem + "px";
      }
    
      setRemUnit();
    
      // reset rem unit on page resize
      window.addEventListener("resize", setRemUnit);
      window.addEventListener("pageshow", function(e) {
        if (e.persisted) {
          setRemUnit();
        }
      });
    
      // detect 0.5px supports
      if (dpr >= 2) {
        var fakeBody = document.createElement("body");
        var testElement = document.createElement("div");
        testElement.style.border = ".5px solid transparent";
        fakeBody.appendChild(testElement);
        docEl.appendChild(fakeBody);
        if (testElement.offsetHeight === 1) {
          docEl.classList.add("hairlines");
        }
        docEl.removeChild(fakeBody);
      }
    })(window, document);
    

    【02】Event Listener相关

    知乎首页上的Event Listener。

    知乎好调皮呀。

     

     

    【03】安装CssRem插件

    Extensions中安装“cssrem" 插件。可以将px 像素转换为 rem。

    找到插件设置,然后需要restart一下,要不然没有显示的。

    更改Rem值,然后可能需要再次重启一下。

     

    【04】编写最终适配代码

    .n (n是名字,名字随便取),enter即可创建一个class为n的分区,然后我们在css中修改n的属性。

    插件安装后 键入 80px 就可以自动转换为1rem了。

    1 rem 其实跟游戏当中的向量归一化差不多,比较直观方便。

    而直接用px的话,它是不会缩放的,因为flexible.js里面写的时候单位是rem,所以我们只有使用rem 单位屏幕才能自适应。

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    .box {
      width: 1rem;
      height: 1rem;
      background-color: rgb(193, 192, 255);
    }
    

     

    
    <html>
        <head>
         <meta charset ="utf-8">
         <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
        <link rel="stylesheet" href="css/test.css">    
    </head>
        <body>
        <div class="box"></div>
            <script src='js/flexible.js'></script>
        </body>
    </html>

    最终适配结果。

     

    2020.8.5

    二、可视化页面头部制作

     


    【2.1】设置body背景图片

    把之前 index.less中测试用的.box 删掉。

    ../ 访问上级文件夹。如 images和css 是同级文件夹,css文件夹下的index.css文件中的bg-image要访问image文件夹中的图片的话,需要 ../

    * {
        margin:0;
        padding:0;
        box-sizing:border-box;
    }
    
    body{
        background:url(../images/bg.jpg)
         no-repeat top center;
         background-size:cover;
      }

     

    【1】top center 居上居中,跟UE4 h/v alignment一样。

    【2】backgroud-size 跟 UE4 Size一样,自动填充。

    • cover完全铺满容器
    • contain 完整显示在容器内
    top center

    【3】还有no-repeat 不重复,指如果有一个37*37px 的图片,而显示器分辨率是3840 * 2160 px,默认是会自动把这张小图片重复填满整个网页的。no-repeat 则将这张小图片设置为不自动重复平铺。


    【2.2】制作头部盒子

    用header标签。

    再次强调一下,px 单位不能自动适应,rem才可以。

    把颜色换成图片。

    html文件。

    <html>
     <head>
     <meta charset ="utf-8">
     <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
     <link rel="stylesheet" href="css/test.css"> 
    </head>
     <body>
     <script src='js/flexible.js'></script>
     <header>
     
     </header>
     </body>
    </html>

    less文件。

    * {
     margin:0;
     padding:0;
     box-sizing:border-box;
    }
    
    body{
     background:url(../images/bg.jpg)
     no-repeat top center;
     background-size:cover;
      }
    
    header {
     height:1.25rem;
     background:url(..//images/head_bg.png)
     no-repeat;
     background-size: 100% 100%;  
     // 水平垂直缩放100%,原大小
    
    
    }

    然后header标题空间我们就配置好了。

     


    【2.3】制作大标题文字

    html文件header标签中添加 h1 一号大标题,中间夹着 “数据可视化-Echarts”字样。

    css文件中font-size要注意转化为rem,这样文字大小也能跟着屏幕自适应变化。

    • font-size字体大小
    • color颜色
    • text-align 文字justification对齐方式
    • line-height 行高

     

    * {
        margin:0;
        padding:0;
        box-sizing:border-box;
    }
    
    body{
        background:url(../images/bg.jpg)
         no-repeat top center;
         background-size:cover;
      }
    
    header {
        height:1.25rem;
        background:url(..//images/head_bg.png)
        no-repeat;
        background-size: 100% 100%;  
        // 水平垂直缩放100%,原大小
        h1{
            font-size: .475rem;
            color: white;
            text-align: center;
            line-height: 1rem;
    
        }
    
    }

     

    文字大小跟随屏幕自适应就弄好了。


    【2.4】配置右侧时间文字 空间

    .showTime 定义division分区showTime。

    <html>
     <head>
     <meta charset ="utf-8">
     <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
     <link rel="stylesheet" href="css/test.css"> 
    </head>
     <body>
     <script src='js/flexible.js'></script>
     <header>
     <h1>数据可视化-ECharts</h1>
     <div class="showTime">12152</div>
     </header>
     </body>
    </html>

    子绝父相,父类header relative相对,子类.showTime absolute绝对,让子类位置相对于父类位置。

    注意top 位置为0,否则文字位置在header的下面。


    【2.5】写showTime时间函数

    // 格式: 当前时间:2020年8月5日11时48分14秒
    <script>
                var t = null;
                t = setTimeout(time, 1000);//開始运行
                function time() {
                    clearTimeout(t);//清除定时器
                    dt = new Date();
                    var y = dt.getFullYear();
                    var mt = dt.getMonth() + 1;
                    var day = dt.getDate();
                    var h = dt.getHours();//获取时
                    var m = dt.getMinutes();//获取分
                    var s = dt.getSeconds();//获取秒
                    document.querySelector(".showTime").innerHTML = '当前时间:' + y + "年" + mt + "月" + day + "日" + h + "时" + m + "分" + s + "秒";
                    t = setTimeout(time, 1000); //设定定时器,循环运行     
                }
     </script>
    

    这个道理都是相通的,用蓝图来写也非常简单。

    X Tesla:【UE4】 如何用蓝图获取本地时间​zhuanlan.zhihu.com图标

    queryselector用于查询 分区showTime,然后innerHTML脚本向分区内写字。

    <html>
        <head>
         <meta charset ="utf-8">
         <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
        <link rel="stylesheet" href="css/test.css">    
    </head>
        <body>
            <script src='js/flexible.js'></script>
            <header>
                <h1>数据可视化-ECharts</h1>
                <div class="showTime"></div>
                // 格式: 当前时间:2020年8月5日11时48分14秒
    <script>
                var t = null;
                t = setTimeout(time, 1000);//開始运行
                function time() {
                    clearTimeout(t);//清除定时器
                    dt = new Date();
                    var y = dt.getFullYear();
                    var mt = dt.getMonth() + 1;
                    var day = dt.getDate();
                    var h = dt.getHours();//获取时
                    var m = dt.getMinutes();//获取分
                    var s = dt.getSeconds();//获取秒
                    document.querySelector(".showTime").innerHTML = '当前时间:' + y + "年" + mt + "月" + day + "日" + h + "时" + m + "分" + s + "秒";
                    t = setTimeout(time, 1000); //设定定时器,循环运行     
                }
     </script>
            </header>
        </body>
    </html>

     

     

    2020.8.5

    三、MainBox 3: 5 :3 布局

    <section>定义文档中的一个区。

    UE4当中可以用Grid Panel来做,但是比较麻烦。用Spacer和H/V Box就可以了。

    header下面新增section mainbox。

    .column*3可以创建三行column class。

      <section class="mainbox">
                <div class="column">1</div>
                <div class="column">2</div>
                <div class="column">3</div>
            </section>

    css中

    • 用flex 来像grid panel 那样灵活地划分区域
    • .column: nth-child(n)来定位column元素并更改其相关flex 布局。
    .mainbox{
        display:flex;
        min-width: 1024px;
        max-width: 1920px;
        margin: auto;
        background-color: green;
        padding: 0.125rem 0.125rem 0;
        .column{
            flex:3;
        }
        .column:nth-child(2) {
            flex:5;
        }
    }

    2020.8.5

    四、Panel 盒子公共面板

     


    就跟UE Vertical Box Horizontal Box 一样的啦。

    【4.1】制作第一个基础 panel 容器(horizontal box)

    我们需要在 column 1 第一列下添加 panel 1,其实就是第一个Vertical Box里面放了三个Horizontal Box。

     <section class="mainbox">
     <div class="column">
     <div class="panel"></div>
     </div>
     <div class="column">2</div>
     <div class="column">3</div>
     </section>

     

    .mainbox{
        display:flex;
        min- 1024px;
        max- 1920px;
        margin:  0 auto;
        padding: 0.125rem 0.125rem 0;
        .column{
            flex:3;
        }
        .column:nth-child(2) {
            flex:5;
        }
        .panel{
            height: 3.875rem;
            background-color: blue;
    
        }
    }

     


    【4.2】细化panel 容器

    【1】添加边框、添加背景图片。

    .panel{
            height: 3.875rem;
            border:1px solid rgba(25,186,139,0.17);
            background-image: url(../images/line(1).png);
    
        }

     

    【2】给panel 内 左右下 一个padding,上面的padding可以用文字代替。

    .panel{
            height: 3.875rem;
            padding: 0  .1875rem .5rem;
            border:1px solid rgba(25,186,139,0.17);
            background-image: url(../images/line(1).png);
    
        }

    【3】制作vertical box 中的第一个horizontal box 和第二个 horizonal box 之间的边距,用margin,margin定义外边距。顺便加个白色,透明度第一点就好了。

      .panel{
            height: 3.875rem;
            padding: 0 .1875rem .5rem;
            border:1px solid rgba(25,186,139,0.17);
            background-image: url(../images/line(1).png) ;
            background-color: rgba(255, 255, 255, .04);
            margin-bottom: .1875rem;
    
        }

     


    【4.3】制作框框外面的四个小边角

    通过border 和before after定位来 制作Panel的四个边角。

    【1】&::before 制作左上角的边角

    .panel{
            position: relative;
            height: 3.875rem;
            padding: 0 .1875rem .5rem;
            border:1px solid rgba(25,186,139,0.17);
            background-image: url(../images/line(1).png) ;
            background-color: rgba(255, 255, 255, .04);
            margin-bottom: .1875rem;
            &::before{
                position: absolute;
                top: 0;
                left: 0;
                 10px;
                height: 10px;
                border-left: 2px solid #02a6b5;
                border-top:  2px solid #02a6b5;
                content: '';
            }
        }

     

     

    【2】&::after 制作右上角的边角

     .panel{
            position: relative;
            height: 3.875rem;
            padding: 0 .1875rem .5rem;
            border:1px solid rgba(25,186,139,0.17);
            background-image: url(../images/line(1).png) ;
            background-color: rgba(255, 255, 255, .04);
            margin-bottom: .1875rem;
            &::before{
                position: absolute;
                top: 0;
                left: 0;
                 10px;
                height: 10px;
                border-left: 2px solid #02a6b5;
                border-top:  2px solid #02a6b5;
                content: '';
            }
    
            &::after{
                position: absolute;
                top: 0;
                right: 0;
                 10px;
                height: 10px;
                border-right: 2px solid #02a6b5;
                border-top:  2px solid #02a6b5;
                content: '';
            }
        }

    【03】】下面两个边角的话需要在panel 分区中再添加一个panel-footer

    <section class="mainbox">
     <div class="column">
     <div class="panel">
     <div class="panel-footer"></div>
     </div>
     </div>
     <div class="column">2</div>
     <div class="column">3</div>
     </section>

    把上面的代码复制一套,注意还是在panel内,跟html中div分区保持一致。

       // panel
        .panel{
            position: relative;
            height: 3.875rem;
            padding: 0 .1875rem .5rem;
            border:1px solid rgba(25,186,139,0.17);
            background-image: url(../images/line(1).png) ;
            background-color: rgba(255, 255, 255, .04);
            margin-bottom: .1875rem;
    
            &::before{
                position: absolute;
                top: 0;
                left: 0;
                 10px;
                height: 10px;
                border-left: 2px solid #02a6b5;
                border-top:  2px solid #02a6b5;
                content: '';
            }
    
            &::after{
                position: absolute;
                top: 0;
                right: 0;
                 10px;
                height: 10px;
                border-right: 2px solid #02a6b5;
                border-top:  2px solid #02a6b5;
                content: '';
            }
    
            //panel -footer
        .panel-footer{
            position: absolute;
            bottom: 0;
            left: 0;
             100%;
    
    
            &::before{
                position: absolute;
                bottom: 0;
                left: 0;
                 10px;
                height: 10px;
                border-left: 2px solid #02a6b5;
                border-bottom:  2px solid #02a6b5;
                content: '';
            }
    
            &::after{
                position: absolute;
                bottom: 0;
                right: 0;
                 10px;
                height: 10px;
                border-right: 2px solid #02a6b5;
                border-bottom:  2px solid #02a6b5;
                content: '';
            }
            
    
        }
    
        }

     

    五、Panel Box 中的文字和图表分区

    【5.1】定义元素

    html中。

    • panel 后面空格加一个 bar,bar panel 类。
    • panel bar中新添加一个一号标题 ,名字为"柱形图-就业行业"
    • panel bar中新建分区名字为chart,之后我们把柱形图表放在这里
       <section class="mainbox">
                <div class="column ">
                <div class="panel bar">
    
                    <h2>柱形图-就业行业</h2>
                    <div class="chart">图表</div>
                <div class="panel-footer"></div>
    
                </div>
                </div>
    
                <div class="column">2</div>
                <div class="column">3</div>
    
                </section>   

     

    【5.2】修饰标题文字

    • less中定义h2 元素(还是在panel 区内)
    • font-weight不加粗文字
    • pane
     h2{
            height:.6rem;
            color: white;
            line-height: .6rem;
            text-align: center;
            font-size: .25rem;
            font-weight: 400;
    
        }

     

    【5.3】修饰图表

     h2{
            height:.6rem;
            color: white;
            line-height: .6rem;
            text-align: center;
            font-size: .25rem;
            font-weight: 400;
    
        }
    
        .chart{
            height: 3rem;
            background-color: red;
        }

     

    【5.4】制作剩下的六个图表

    不断复制就好了。

            <section class="mainbox">
                 <div class="column ">
    
                    <div class="panel bar">
                    <h2>柱形图-就业行业</h2>
                    <div class="chart"></div>
                     <div class="panel-footer"></div>
                     </div>
    
                     <div class="panel line">
                        <h2>柱形图-就业行业</h2>
                        <div class="chart"></div>
                         <div class="panel-footer"></div>
                         </div>
    
                         <div class="panel pie">
                            <h2>柱形图-就业行业</h2>
                            <div class="chart"></div>
                             <div class="panel-footer"></div>
                             </div>
    
                </div>
                </div> 
    
                <div class="column">2</div>
    
                <div class="column">
                    
                    <div class="panel bar">
                        <h2>柱形图-就业行业</h2>
                        <div class="chart"></div>
                         <div class="panel-footer"></div>
                         </div>
        
                         <div class="panel line">
                            <h2>柱形图-就业行业</h2>
                            <div class="chart"></div>
                             <div class="panel-footer"></div>
                             </div>
        
                             <div class="panel pie">
                                <h2>柱形图-就业行业</h2>
                                <div class="chart"></div>
                                 <div class="panel-footer"></div>
                                 </div>
    
                            
                </div>
                
            </section>   

    当前的LESS文件:

    * {
        margin:0;
        padding:0;
        box-sizing:border-box;
    }
    
    body{
        background:url(../images/bg.jpg)
         no-repeat top center;
         background-size:cover;
      }
    
    header {
        position: relative;
        height:1.25rem;
        background:url(..//images/head_bg.png)
        no-repeat;
        background-size: 100% 100%;  
        // 水平垂直缩放100%,原大小
        h1{
            font-size: .475rem;
            color: white;
            text-align: center;
            line-height: 1rem;
        }
        .showTime{
            position: absolute;
            font-size: .25rem;
            right: .375rem;
            // 代替text-align,指定具体的偏移对齐位置
            top:0;
            line-height: .9375rem;
            color: rgba(255, 255, 255, .7);
            
        }
    }
    
    .mainbox{
        display:flex;
        min- 1024px;
        max- 1920px;
        margin:  0 auto;
        padding:  0.125rem 0.125rem 0;
        .column{
            flex:3;
        }
        .column:nth-child(2) {
            flex:5;
        }
    
        // panel
        .panel{
            position: relative;
            height: 3.875rem;
            padding: 0 .1875rem .5rem;
            border:1px solid rgba(25,186,139,0.17);
            background-image: url(../images/line(1).png) ;
            background-color: rgba(255, 255, 255, .04);
            margin-bottom: .1875rem;
    
            &::before{
                position: absolute;
                top: 0;
                left: 0;
                 10px;
                height: 10px;
                border-left: 2px solid #02a6b5;
                border-top:  2px solid #02a6b5;
                content: '';
            }
    
            &::after{
                position: absolute;
                top: 0;
                right: 0;
                 10px;
                height: 10px;
                border-right: 2px solid #02a6b5;
                border-top:  2px solid #02a6b5;
                content: '';
            }
    
            //panel -footer
        .panel-footer{
            position: absolute;
            bottom: 0;
            left: 0;
             100%;
    
    
            &::before{
                position: absolute;
                bottom: 0;
                left: 0;
                 10px;
                height: 10px;
                border-left: 2px solid #02a6b5;
                border-bottom:  2px solid #02a6b5;
                content: '';
            }
    
            &::after{
                position: absolute;
                bottom: 0;
                right: 0;
                 10px;
                height: 10px;
                border-right: 2px solid #02a6b5;
                border-bottom:  2px solid #02a6b5;
                content: '';
            }
            
    
        }
        h2{
            height:.6rem;
            color: white;
            line-height: .6rem;
            text-align: center;
            font-size: .25rem;
            font-weight: 400;
    
        }
    
        .chart{
            height: 3rem;
            background-color: red;
        }
        }
      
    }
    

     

     

    2020.8.5

    六、数字模块布局


    【6.1】制作数字模块空间 no

     

    上方放number,下面放文字。第六节制作这个no模块。

      <div class="column">
                    <div class="no">上部数字</div>
                </div>
    

     

     .no{
            background: rgba(101, 132, 226, .1);
            padding: .1875rem;
            
        }

     

    需要在第二列中添加一个边距值,要不然是跟左右两列紧挨着的。

    .column:nth-child(2) {
            flex:5;
            margin: 0 .125rem .1875rem;

    【6.2】划分数字模块成数字和文字两个区域

    将no 模块划分为上面的hd(head)存放数字,下面的bd(body)存放文字说明。

    <div class="column">
                    <div class="no">
                        <div class="no-hd">数字</div>
                        <div class="no-bd">文字</div>
                    </div>
    
                </div>
    

    【6.3】定义数字区边框

    先给数字no-hd个边框。

    .no{
            background: rgba(101, 132, 226, .1);
            
            padding: .1875rem;
            .no-hd{
                border: 1px solid rgba(25, 186, 139, .17);
            }
            
        }

     


    【6.4】用list 将border撑开

    有序列表,无序列表很常用的。

    • ol 就是 ordered list 有序列表简称
    • ul 就是unordered list 无序列表简称
    • li 就是list 列表
     <div class="column">
                    <div class="no">
                        <div class="no-hd">
                            <ul>
                                <li>123456</li>
                                <li>100000</li>
                            </ul>
                        </div>
                        <div class="no-bd">文字</div>
                    </div>

    还是用flex 来均匀分配。

      .no{
            background: rgba(101, 132, 226, .1);
            
            padding: .1875rem;
            .no-hd{
                border: 1px solid rgba(25, 186, 139, .17);
            }
            ul{
                display: flex;
                li{
                    flex:1;
                }
            }
        }

     


    【6.5】设置数字特性

    .no{
            background: rgba(101, 132, 226, .1);
            
            padding: .1875rem;
            .no-hd{
                border: 1px solid rgba(25, 186, 139, .17);
            }
            ul{
                display: flex;
                li{
                    flex:1;
                    line-height: 1rem;
                    font: size .875rem;
                    color:#ffeb7b;
                    text-align:center;
                }
            }
        }

    然后li 初始化(跟body 一样都放在外层)的时候设置list-style为none这样那个小圆点就没了。

    li{
        list-style: none;
    }

     


    【6.6】优化文字字体

    ttf格式的字体样式已经在资源包中了。

    我们需要跟那个li 初始化一样来定义我们的字体。

    @font-face{
        font-family:electronicFont;
        src:url(../font/DS-DIGIT.TTF)
    }

    然后对应文字名字。

     .no{
            background: rgba(101, 132, 226, .1);
            
            padding: .1875rem;
            .no-hd{
                border: 1px solid rgba(25, 186, 139, .17);
            }
            ul{
                display: flex;
                li{
                    flex:1;
                    line-height: 1rem;
                    font-size: .875rem;
                    color:#ffeb7b;
                    text-align:center;
                    font-family: "electronicFont";
                }
            }
        }

    【6.7】制作边角

    还是用&::before,&::after。注意如果出不来的话,父绝子相哈。

    因为要定在数字边框处,所以relative要在 no-bd下,也就是no-bd要当爹。

        .no{
            
            background: rgba(101, 132, 226, .1);
            
            padding: .1875rem;
            .no-hd{
                border: 1px solid rgba(25, 186, 139, .17);
                position: relative;
            
    
            &::before{
                position:absolute;
                top:0;
                left:0;
                content:"";
                 30px;
                height: 10px;
                border-top: 2px solid #02a6b5;
                border-left:2px solid #02a6b5;
            }
    
            &::after{
                position:absolute;
                bottom:0;
                right:0;
                content:"";
                 30px;
                height: 10px;
                border-bottom: 2px solid #02a6b5;
                border-right:2px solid #02a6b5;
            }
        }
    
            ul{
                display: flex;
                li{
                    flex:1;
                    line-height: 1rem;
                    font-size: .875rem;
                    color:#ffeb7b;
                    text-align:center;
                    font-family: "electronicFont";
                }
            }
        }
    }

     


     

    【6.8】制作中间的小竖线

    还是用伪元素来做。

      ul{
                display: flex;
                li{
                    position: relative;
                    flex:1;
                    line-height: 1rem;
                    font-size: .875rem;
                    color:#ffeb7b;
                    text-align:center;
                    font-family: "electronicFont";
                    &::after{
                        content: "";
                        position: absolute;
                        top:25%;
                        right:0;
                        height: 50%;
                         1px;
                        background-color: rgba(255, 255, 255, .2);
                    }
                }  

     

     

    【6.9】制作数字下的文字

    ul>li*2可快速制作无序列表

       .no-bd{
            ul{
                display:flex;
                li{
                    flex:1;
                    color:rgba(255, 255, 255, .7);
                    font-size:0.225rem;
                    height:.5rem;
                    line-height: .5rem;
                    padding-top: .125rem;
                }
            }
        }   

     

      <div class="column">
                    <div class="no">
                        <div class="no-hd">
                            <ul>
                                <li>123456</li>
                                <li>100000</li>
                            </ul>
                        </div>
                        <div class="no-bd">
                            <ul>
                                <li>虚幻引擎需求人数</li>
                                <li>虚幻引擎供应人数</li>
                            </ul>
                        </div>
                    </div>

     

     

     

    七、制作map模块

    可以看到map模块分为四个元素:

    • 中国 地图模块
    • 后面六边形地球图片
    • 箭头旋转图片
    • 点状不规则形状图片

    【7.1】配置map基础空间

    div map 分区。

      <div class="column">
    
                    <div class="no">
                        <div class="no-hd">
                            <ul>
                                <li>123456</li>
                                <li>100000</li>
                            </ul>
                        </div>
                        <div class="no-bd">
                            <ul>
                                <li>虚幻引擎需求人数</li>
                                <li>虚幻引擎供应人数</li>
                            </ul>
                        </div>
                    
                        <div class="map"></div>
    
                    </div>
    
                </div>

    加高度和颜色测试。

    .map{
            
            height:10.125rem;
            background-color: red;
    
        }

     


    【7.2】放置球体图片

    居中。

      <div class="map">
                            <div class="map1"></div>
                        </div>
    
                    </div>
    

     

     .map{
            position: relative;
            height:10.125rem;
    
           .map1{
                6.475rem;
               height:6.475rem;
               position: absolute;
               top:50%;
               left:50%;
            //    水平居中 垂直居中
               transform:translate(-50%,-50%);
               background: url(../images/map.png);
               
               //让图片也能跟着缩放
               background-size: 100% 100%;
               opacity: 0.3;
    
           }
    
        }

     

     


    【7.3】旋转不规则图片

     

              <div class="column">
    
                    <div class="no">
                        <div class="no-hd">
                            <ul>
                                <li>123456</li>
                                <li>100000</li>
                            </ul>
                        </div>
                        <div class="no-bd">
                            <ul>
                                <li>虚幻引擎需求人数</li>
                                <li>虚幻引擎供应人数</li>
                            </ul>
                        </div>
                    
                        <div class="map">
                            <div class="map1"></div>
                            <div class="map2"></div>
                        </div>
    
                    </div>
    
                </div>

     

    调用keyframes 动画,跟ue差不多,多少秒内转多少度。

     .map2{
     position: absolute;
     top: 50%;
     left: 50%;
     transform:translate(-50%,-50%);
     width:8.0375rem ;
     height:8.0375rem;
     background: url(../images/lbx.png);
     background-size: 100% 100%;
    
     animation: rotate1 15s linear infinite;
    
           }
    
     @keyframes rotate1 {
               from{
     transform: translate(-50%,-50%) rotate(0deg);  
               }
    
               to{
     transform: translate(-50%,-50%) rotate(360deg);  
               }

     


    【7.4】逆时针旋转箭头

     

    可以 opacity改图片不透明度。

    <div class="map">
                            <div class="map1"></div>
                            <div class="map2"></div>
                            <div class="map3"></div>
                        </div>
    
                    </div>

     

     

        .map{
            position: relative;
            height:10.125rem;
    
           .map1{
                6.475rem;
               height:6.475rem;
               position: absolute;
               top:50%;
               left:50%;
            //    水平居中 垂直居中
               transform:translate(-50%,-50%);
               background: url(../images/map.png);
    
               //让图片也能跟着缩放
               background-size: 100% 100%;
               opacity: 0.3;
    
           }
    
           .map2{
               position: absolute;
               top: 50%;
               left: 50%;
               transform:translate(-50%,-50%);
               8.0375rem ;
               height:8.0375rem;
               background: url(../images/lbx.png);
               background-size: 100% 100%;
               opacity: 0.6;
    
               animation: rotate1 15s linear infinite;
    
           }
    
           .map3{
            position: absolute;
            top: 50%;
            left: 50%;
            transform:translate(-50%,-50%);
             7.075rem ;
            height:7.075rem;
            background: url(../images/jt.png);
            background-size: 100% 100%;
            opacity: 0.6;
    
            animation: rotate2 10s linear infinite;
    
        }
    
           @keyframes rotate1 {
               from{
                   transform: translate(-50%,-50%) rotate(0deg);  
               }
    
               to{
                transform: translate(-50%,-50%) rotate(360deg);  
               }
                }
    
            @keyframes rotate2 {
                from{
                    transform: translate(-50%,-50%) rotate(0deg);  
                }
     
                to{
                 transform: translate(-50%,-50%) rotate(-360deg);  
                }
    

     


    【7.5】添加地图模块

     

    <div class="map">
                            <div class="map1"></div>
                            <div class="map2"></div>
                            <div class="map3"></div>
                            <div class="chart">地图模块</div>
                        </div>

    可以先将bgcolor ctrl+/ 注释掉,后面直接放地图就好了。

      .chart{
            position: absolute;
            top: 0;
            left: 0;
            background-color: red;
            10.125rem ;
            height:10.125rem ;
    
        }

     

     


     

    好了,终于完成了第一节的页面基础配置了呢,剩下就是放Echarts图表了。

    布局整个html文件:

    <html>
        <head>
         <meta charset ="utf-8">
         <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
        <link rel="stylesheet" href="css/test.css">    
    </head>
        <body>
            <script src='js/flexible.js'></script>
            <header>
                <h1>数据可视化-ECharts</h1>
                <div class="showTime"></div>
                
    <script>
                var t = null;
                t = setTimeout(time, 1000);//開始运行
                function time() {
                    clearTimeout(t);//清除定时器
                    dt = new Date();
                    var y = dt.getFullYear();
                    var mt = dt.getMonth() + 1;
                    var day = dt.getDate();
                    var h = dt.getHours();//获取时
                    var m = dt.getMinutes();//获取分
                    var s = dt.getSeconds();//获取秒
                    document.querySelector(".showTime").innerHTML = '当前时间:' + y + "年" + mt + "月" + day + "日" + h + "时" + m + "分" + s + "秒";
                    t = setTimeout(time, 1000); //设定定时器,循环运行     
                }
     </script>
            </header>
    
         
            <section class="mainbox">
                 <div class="column ">
    
                    <div class="panel bar">
                    <h2>柱形图-就业行业</h2>
                    <div class="chart"></div>
                     <div class="panel-footer"></div>
                     </div>
    
                     <div class="panel line">
                        <h2>柱形图-就业行业</h2>
                        <div class="chart"></div>
                         <div class="panel-footer"></div>
                         </div>
    
                         <div class="panel pie">
                            <h2>柱形图-就业行业</h2>
                            <div class="chart"></div>
                             <div class="panel-footer"></div>
                             </div>
    
                </div>
                </div> 
    
    
                <div class="column">
    
                    <div class="no">
                        <div class="no-hd">
                            <ul>
                                <li>123456</li>
                                <li>100000</li>
                            </ul>
                        </div>
                        <div class="no-bd">
                            <ul>
                                <li>虚幻引擎需求人数</li>
                                <li>虚幻引擎供应人数</li>
                            </ul>
                        </div>
                    
                        <div class="map">
                            <div class="map1"></div>
                            <div class="map2"></div>
                            <div class="map3"></div>
                            <div class="chart">地图模块</div>
                        </div>
    
                    </div>
    
                </div>
    
                <div class="column">
                    
                    <div class="panel bar">
                        <h2>柱形图-就业行业</h2>
                        <div class="chart"></div>
                         <div class="panel-footer"></div>
                         </div>
        
                         <div class="panel line">
                            <h2>柱形图-就业行业</h2>
                            <div class="chart"></div>
                             <div class="panel-footer"></div>
                             </div>
        
                             <div class="panel pie">
                                <h2>柱形图-就业行业</h2>
                                <div class="chart"></div>
                                 <div class="panel-footer"></div>
                                 </div>
    
                            
                </div>
    
            </section>   
        </body>
    </html>

     

    布局整个LESS 文件

    * {
        margin:0;
        padding:0;
        box-sizing:border-box;
    }
    
    li{
        list-style: none;
    }
    
    @font-face{
        font-family:electronicFont;
        src:url(../font/DS-DIGIT.TTF)
    }
    
    body{
        background:url(../images/bg.jpg)
         no-repeat top center;
         background-size:cover;
      }
    
    header {
        position: relative;
        height:1.25rem;
        background:url(..//images/head_bg.png)
        no-repeat;
        background-size: 100% 100%;  
        // 水平垂直缩放100%,原大小
        h1{
            font-size: .475rem;
            color: white;
            text-align: center;
            line-height: 1rem;
        }
        .showTime{
            position: absolute;
            font-size: .25rem;
            right: .375rem;
            // 代替text-align,指定具体的偏移对齐位置
            top:0;
            line-height: .9375rem;
            color: rgba(255, 255, 255, .7);
            
        }
    }
    
    .mainbox{
        display:flex;
        min- 1024px;
        max- 1920px;
        margin:  0 auto;
        padding:  0.125rem 0.125rem 0;
        .column{
            flex:3;
        }
        .column:nth-child(2) {
            flex:5;
            margin: 0 .125rem .1875rem;
        }
    
        // panel
        .panel{
            position: relative;
            height: 3.875rem;
            padding: 0 .1875rem .5rem;
            border:1px solid rgba(25,186,139,0.17);
            background-image: url(../images/line(1).png) ;
            background-color: rgba(255, 255, 255, .04);
            margin-bottom: .1875rem;
    
            &::before{
                position: absolute;
                top: 0;
                left: 0;
                 10px;
                height: 10px;
                border-left: 2px solid #02a6b5;
                border-top:  2px solid #02a6b5;
                content: '';
            }
    
            &::after{
                position: absolute;
                top: 0;
                right: 0;
                 10px;
                height: 10px;
                border-right: 2px solid #02a6b5;
                border-top:  2px solid #02a6b5;
                content: '';
            }
    
            //panel -footer
        .panel-footer{
            position: absolute;
            bottom: 0;
            left: 0;
             100%;
    
    
            &::before{
                position: absolute;
                bottom: 0;
                left: 0;
                 10px;
                height: 10px;
                border-left: 2px solid #02a6b5;
                border-bottom:  2px solid #02a6b5;
                content: '';
            }
    
            &::after{
                position: absolute;
                bottom: 0;
                right: 0;
                 10px;
                height: 10px;
                border-right: 2px solid #02a6b5;
                border-bottom:  2px solid #02a6b5;
                content: '';
            }
            
    
        }
        h2{
            height:.6rem;
            color: white;
            line-height: .6rem;
            text-align: center;
            font-size: .25rem;
            font-weight: 400;
    
        }
    
        .chart{
            height: 3rem;
            background-color: red;
        }
        }
        
        .no{
            
            background: rgba(101, 132, 226, .1);
            
            padding: .1875rem;
            .no-hd{
                border: 1px solid rgba(25, 186, 139, .17);
                position: relative;
            
    
            &::before{
                position:absolute;
                top:0;
                left:0;
                content:"";
                 30px;
                height: 10px;
                border-top: 2px solid #02a6b5;
                border-left:2px solid #02a6b5;
            }
    
            &::after{
                position:absolute;
                bottom:0;
                right:0;
                content:"";
                 30px;
                height: 10px;
                border-bottom: 2px solid #02a6b5;
                border-right:2px solid #02a6b5;
            }
        }
    
        .no-bd{
            ul{
                display:flex;
                li{
                    flex:1;
                    color:rgba(255, 255, 255, .7);
                    font-size:0.225rem;
                    height:.5rem;
                    line-height: .5rem;
                    
                }
            }
        }
            ul{
                display: flex;
                li{
                    position: relative;
                    flex:1;
                    line-height: 1rem;
                    font-size: .875rem;
                    color:#ffeb7b;
                    text-align:center;
                    font-family: "electronicFont";
                    &::after{
                        content: "";
                        position: absolute;
                        top:25%;
                        right:0;
                        height: 50%;
                         1px;
                        background-color: rgba(255, 255, 255, .2);
                    }
                }
            }
        }
    
        .map{
            position: relative;
            height:10.125rem;
    
           .map1{
                6.475rem;
               height:6.475rem;
               position: absolute;
               top:50%;
               left:50%;
            //    水平居中 垂直居中
               transform:translate(-50%,-50%);
               background: url(../images/map.png);
    
               //让图片也能跟着缩放
               background-size: 100% 100%;
               opacity: 0.3;
    
           }
    
           .map2{
               position: absolute;
               top: 50%;
               left: 50%;
               transform:translate(-50%,-50%);
               8.0375rem ;
               height:8.0375rem;
               background: url(../images/lbx.png);
               background-size: 100% 100%;
               opacity: 0.6;
    
               animation: rotate1 15s linear infinite;
    
           }
    
           .map3{
            position: absolute;
            top: 50%;
            left: 50%;
            transform:translate(-50%,-50%);
             7.075rem ;
            height:7.075rem;
            background: url(../images/jt.png);
            background-size: 100% 100%;
            opacity: 0.6;
    
            animation: rotate2 10s linear infinite;
    
        }
    
        .chart{
            position: absolute;
            top: 0;
            left: 0;
            // background-color: red;
            10.125rem ;
            height:10.125rem ;
    
        }
    
           @keyframes rotate1 {
               from{
                   transform: translate(-50%,-50%) rotate(0deg);  
               }
    
               to{
                transform: translate(-50%,-50%) rotate(360deg);  
               }
                }
    
            @keyframes rotate2 {
                from{
                    transform: translate(-50%,-50%) rotate(0deg);  
                }
     
                to{
                 transform: translate(-50%,-50%) rotate(-360deg);  
                }
    
    
    
               
    
    
               
           }
    
        }
    }
    

     

    编辑于 2020-08-05

    ECharts数据可视化项目-大屏数据可视化展示-echarts 图表制作-pink老师直播课更

    接着第二章

     

    学完第三章

     

     

     

    我有点强迫症,今日事必须今日毕,不管晚上搞到几点。

    【导图】

     


     

    一、Echarts介绍

    【1.1】其他相关常见的数据可视化库

    • D3.js 目前 Web 端评价最高的 Javascript 可视化工具库(入手难)
    • ECharts.js 百度出品的一个开源 Javascript 数据可视化库
    • Highcharts.js 国外的前端数据可视化库,非商用免费,被许多国外大公司所使用
    • AntV 蚂蚁金服全新一代数据可视化解决方案 等等
    • Highcharts 和 Echarts 就像是 Office 和 WPS 的关系

    【1.2】Echarts简介

    ECharts,一个使用 JavaScript 实现的开源可视化库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8/9/10/11,Chrome,Firefox,Safari等),底层依赖矢量图形库 ZRender,提供直观,交互丰富,可高度个性化定制的数据可视化图表。

    【1.3】Echarts常用图表

    有官方版和社区版。

     

     

    二、五分钟快速上手Echarts

    五分钟快速上手Echarts​echarts.apache.org
    1. 下载并引入Echarts.js文件(要生成的图表需要依赖这个js库才能实现)
    2. 准备一个具有特定大小的DOM容器,以把我们的图表放置于其中,而且容器必须要有宽度和高度。(我们第二章中已经配置完毕了)
    3. 初始化echarts实例对象
    4. 指定配置项和数据
    5. 将配置项设置给Echarts实例对象

     


    【2.1】下载并引入echarts.js文件

    下载好后将这个echarts.min.js放置在js文件夹内,方便我们调用。

    然后body中引入echarts脚本就好了。

    <html>
     <head>
     <meta charset ="utf-8">
     <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
     </head>
     <body>
         <script src='js/echarts.min.js'></script>
     </body>
    </html>

     


    【2.2】准备DOM容器,给容器配置高度宽度

    1. .box分区
    2. head中内嵌css文件
    <html>
     <head>
     <meta charset ="utf-8">
     <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
     <style>
         .box{
             width: 300px;
             height: 300px;
             background-color: green;
         }
     </style>
     </head>
     <body>
         <div class="box"></div>
         <script src='js/echarts.min.js'></script>
     </body>
    </html>

     

     

    【2.3】实例化echarts对象

    • echarts.init()来实例化
    • document.querySelector()来查询dom容器并写入图表
    <html>
     <head>
     <meta charset ="utf-8">
     <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
     <style>
         .box{
             width: 300px;
             height: 300px;
             background-color: green;
         }
     </style>
     </head>
     <body>
         <div class="box"></div>
         <script src='js/echarts.min.js'></script>
         <script>
            //  初始化实例对象 echarts.init(DOM容器)
             var xtesla = echarts.init(document.querySelector(".box"));
    
         </script>
     </body>
    </html>

     


    【2.4】指定配置项和数据

    • var option来配置图表数据
    • 复制教程内的set option
    Documentation - Apache ECharts(incubating)​echarts.apache.org
    <html>
     <head>
     <meta charset ="utf-8">
     <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
     <style>
         .box{
             width: 500px;
             height: 500px;
             background-color: green;
         }
     </style>
     </head>
     <body>
         <div class="box"></div>
         <!-- 引入echarts 图表 -->
         <script src='js/echarts.min.js'></script>
         <script>
            //  初始化实例对象 echarts.init(DOM容器)
             var xtesla = echarts.init(document.querySelector(".box"));
             //指定配置项和数据
    
             var option = {
                title: {
                    text: 'ECharts 入门示例'
                },
                tooltip: {},
                legend: {
                    data:['销量']
                },
                xAxis: {
                    data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
                },
                yAxis: {},
                series: [{
                    name: '销量',
                    type: 'bar',
                    data: [5, 20, 36, 10, 10, 20]
                }]
            };
    
           
         </script>
     </body>
    </html>

     


    【2.5】将配置项设置给echarts实例对象

    <html>
     <head>
     <meta charset ="utf-8">
     <!-- char字符 set集  字符集,使用UTF-8编码,浏览器上可以显示各国语言的文字,不必下载相关语言支持包 -->
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <!--viewport窗口,width设置网页布局宽度,device-width为设备物理宽度,initial-scale设置初始缩放值  -->
     <style>
         .box{
             width: 500px;
             height: 500px;
             background-color: green;
         }
     </style>
     </head>
     <body>
         <div class="box"></div>
         <!-- 引入echarts 图表 -->
         <script src='js/echarts.min.js'></script>
         <script>
            //  初始化实例对象 echarts.init(DOM容器)
             var xtesla = echarts.init(document.querySelector(".box"));
             //指定配置项和数据
    
             var option = {
                title: {
                    text: 'ECharts 入门示例'
                },
                tooltip: {},
                legend: {
                    data:['销量']
                },
                xAxis: {
                    data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
                },
                yAxis: {},
                series: [{
                    name: '销量',
                    type: 'bar',
                    data: [5, 20, 36, 10, 10, 20]
                }]
            };
             // 将配置项设置给echarts实例对象
              xtesla.setOption(option);
    
           
         </script>
     </body>
    </html>

    然后基础入门就入门成功了。

     

     

    三、Echarts 基础配置

    Examples - Apache ECharts (incubating)​echarts.apache.org

    官网文档中找到配置项手册,就可以找到图表所有的属性了。

    Documentation - Apache ECharts(incubating)​echarts.apache.org

    我们拿这个折线图来举例。

    每个配置后面都要用逗号隔开。

    【01 基本图表配置】

    • title——标题(html中的title标签定义网页标签页的名字,默认是xxx.html)
    • tooltip——提示框(鼠标悬浮的时候出现的框框)
      • trigger——触发方式
        • axis放在坐标轴上显示框框 (多个数据排列)
        • item放在单个元素上显示框框(单个数据)
        • none 不触发
    • legend——图例组件,如果series中对象有name,那么legend中的data可以删掉。
    • toolbox——工具箱组件(如保存图片、下载内容)

    【02 坐标系相关配置】

    • grid——网格配置(注意跟DOM容器的区别),grid可以控制线型图、柱状图的图表大小。
      • left right bottom top 定义grid网格和DOM容器之间的距离
      • containLabel 是否显示刻度值,true显示,false不显示
    • xAxis/ yAxis——设置X轴的相关配置
      • type 坐标轴类型
        • category 类目轴(自定义数据类别)
        • value 数值轴(数字)
      • boundaryGap 是否让坐标轴跟内容之间有缝隙(一般为false)

    【03 系列图表配置】

    series后面跟的是数组,数组内对象的名字要跟legend图例组件中的名字要保持一致,而删掉一个对象的话,legend对应的这个图例名称也会消失;当然可以直接删掉legend中的data,因为是会根据series中的name自动生成的嘛 。

     

    • name——图表
    • type——图表样式,它决定显示哪种类别的图表
      • line 线条
      • bar 柱状图
      • pie 饼状图
    • stack——数据堆叠(一般不需要),如果true的话,第二个对象的数据会在第一个对象的数据基础上进行叠加,如第一个对象第一个数据为120,第二个对象第一个数据为150。
      • true的话,第二个会变成270在图表上排布
      • false的话,第二个还是150在图表上排布
    • data——每条线上相关的数据

     

    给定线条不同的颜色,注意要把代码写在跟title、series同级下。(注意最后面的逗号哈)

    color:['red',"green","skyblue","white","blue"],

     

     

    四、竖直柱状图的制作

    【4.1】引入基础竖直柱状图

     

    我们可以使用这个坐标轴刻度与标签对齐 柱状图图表。

    Examples - Apache ECharts (incubating)​echarts.apache.org
    1. 我们先跟之前一样,引入echarts.js ,注意Echarts.js在html中放置的顺序也很有讲究,要放在section mainbox 后执行。
    2. 然后再在js文件夹中新建一个index.js 文件专门来存放我们的图表配置,然后html中同样引入。
    3. 使用立即执行函数,防止变量污染,局部变量。省得定义mychart1,mychart2了。
    4. queryselector柱状图中的图表。
    5. 别忘了给option 前加var,定义option变量。
    //柱状图模块1
    (function(){
        //1.实例化对象
        var myChart=echarts.init(document.querySelector(".bar .chart"));
        //2.指定配置项和数据 option
        var option = {
            color: ['#3398DB'],
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器,坐标轴触发有效
                    type: 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
                    axisTick: {
                        alignWithLabel: true
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '直接访问',
                    type: 'bar',
                    barWidth: '60%',
                    data: [10, 52, 200, 334, 390, 330, 220]
                }
            ]
        };
    
        //3.将配置项给到echarts实例对象
    
        myChart.setOption(option);
        
    
    })();
    

     


    【4.2】自定义柱状图图表 整体和x 轴

    【1】修改柱形颜色,直接改 color:['xxxxxx'],

    【2】修改图表大小,直接改grid

    【3】修改横坐标轴刻度文字颜色、大小。

    axislabel 坐标轴刻度标签。

    【4】不显示x坐标轴样式

    axisline show

     

      var option = {
            //修改柱形颜色
            color: ['#2f89cf'],
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器,坐标轴触发有效
                    type: 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                }
            },
    
            //修改图表大小
            grid: {
                left: '0%',
                top: '10%',
                right:'0%',
                bottom: '4%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
                    axisTick: {
                        alignWithLabel: true
                    },
                    //修改横轴刻度文字颜色
                    axisLabel:{
                        color:"rgba(255,255,255,.6)",
                        fontsize:12,
                    },
                    axisLine:{
                        show:false
                    }
                    //
                }
            ],
    

     

     


    【4.3】自定义柱状图图表 y 轴

    【1】改 label 字体颜色和大小

    axislabel.color/fontsize

    【2】改y轴线条样式

    axisline.linestyle.color/width

    【3】改y轴分割线样式

    splitline.linestyle.color/width

     

       yAxis: [
                {
                    type: 'value',
                    axisLabel:{
                        color:"rgba(255,255,255,.6)",
                        fontsize:12,
                    },
                    //修改y轴线条样式
    
                    axisLine:{
                        LineStyle:{
                            color:"rgba(255,255,255,.1)",
                            width:2
                        }
                    },
    
                    splitLine:{
                        lineStyle:{
                            color:"rgba(255,255,255,.1)",
                           
                        }
    
                    }
                }
            ],
    

     


    【4.4】最终自定义柱状图图表

    【1】柱状图变细,直角变圆角

            series: [
                {
                    name: '直接访问',
                    type: 'bar',
                    //修改bar的宽度
                    barWidth: '35%',
                    data: [10, 52, 200, 334, 390, 330, 220],
    
                    //直角变圆角
                    itemStyle:{
                        barBorderRadius:5
                    }
                }
            ]
        };
    

    【2】更改tooltip悬浮框背景(可选,shadow好看点)

      //修改柱形颜色
            color: ['#2f89cf'],
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器,坐标轴触发有效
                    type: 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                }
            },
    

     

    【3】更换xy轴对应数据

    //柱状图模块1
    (function(){
        //1.实例化对象
        var myChart=echarts.init(document.querySelector(".bar .chart"));
        //2.指定配置项和数据 option
        var option = {
            //修改柱形颜色
            color: ['#2f89cf'],
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器,坐标轴触发有效
                    type: 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                }
            },
    
            //修改图表大小
            grid: {
                left: '0%',
                top: '10%',
                right:'0%',
                bottom: '4%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: [ "旅游行业","教育培训", "游戏行业", "医疗行业", "电商行业", "社交行业", "金融行业" ],
                    axisTick: {
                        alignWithLabel: true
                    },
                    //修改横轴刻度文字颜色
                    axisLabel:{
                        color:"rgba(255,255,255,.6)",
                        fontsize:12,
                    },
                    axisLine:{
                        show:false
                    }
                    //
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    axisLabel:{
                        color:"rgba(255,255,255,.6)",
                        fontsize:12,
                    },
                    //修改y轴线条样式
    
                    axisLine:{
                        LineStyle:{
                            color:"rgba(255,255,255,.1)",
                            width:2
                        }
                    },
    
                    splitLine:{
                        lineStyle:{
                            color:"rgba(255,255,255,.1)",
                           
                        }
    
                    }
                }
            ],
            series: [
                {
                    name: '直接访问',
                    type: 'bar',
                    //修改bar的宽度
                    barWidth: '35%',
                    data: [200, 300, 300, 900, 1500, 1200, 600],
    
                    //直角变圆角
                    itemStyle:{
                        barBorderRadius:5
                    }
                }
            ]
        };
    
        //3.将配置项给到echarts实例对象
    
        myChart.setOption(option);
        
    
    })();
    

     

     


    【4.5】图表跟随屏幕自适应

        //4. 让图表跟随屏幕自适应
    
        window.addEventListener("resize",function(){
            myChart.resize();
        })
    

     

     

     

     

    五、学习进度柱形图(水平柱状图)

    我们用这个水平柱状图

    https://echarts.apache.org/examples/zh/editor.html?c=bar-y-category​echarts.apache.org

     

    【5.1】导入水平柱状图

     

    1. charts.js中新建 水平柱状图立即执行模块 (function(){ })();
    2. index.html中第三列图表panel 重命名 bar2 line2 pie2 这样子。
    3. charts.js中实例对象、指定配置数据、把配置给实例对象
        // 二、水平柱状图
    
    
        (function(){
    
            // 1.实例化echarts对象
            var myChart= echarts.init(document.querySelector(".bar2 .chart"));
    
            // 指定配置和数据
    
           var option = {
        
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
               
                grid: {
                    left: '3%',
                    right: '4%',
                    top:'0%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'value',
                    boundaryGap: [0, 0.01]
                },
                yAxis: {
                    type: 'category',
                    data: ['巴西', '印尼', '美国', '印度', '中国', '世界人口(万)']
                },
                series: [
                    {
                        name: '2011年',
                        type: 'bar',
                        data: [18203, 23489, 29034, 104970, 131744, 630230]
                    },
                    {
                        name: '2012年',
                        type: 'bar',
                        data: [19325, 23438, 31000, 121594, 134141, 681807]
                    }
                ]
            };
    
    
            myChart.setOption(option);
        
    
        })();
    

    还是注意哈,如果出不来就是echarts.min.js和charts.js在index.html中放置的位置不对,不要放在开头,而要放在结尾处。

     


     

    【5.2】调整图像

     

    【1】修改图形大小,grid中设置

     grid: {
                    left: '22%',
                    right: '0%',
                    top:'10%',
                    bottom: '10%',
                    containLabel: true
                },
    

    【2】不显示x轴

    //不显示x轴的相关信息
                xAxis: {
                    show:false,
                },

    【3】不显示y轴线和相关刻度(短横线)

    axisLine:
                    {
                        show:false
                    },
                    axisTick:
                    {show:false,},
    

    【4】设置y轴文字(刻度标签)颜色为白色

    axisLabel:{
                        color:"#fff",
                    },
    

     


    【5.3】修改第一组bar

     

    【1】containLabel包含标签注释掉,这样上面那个 22%left 就直接是里面的图表相对于外面的DOM容器,文字 标签排外,也就是竖直文字标签跟图表不是一个区域内了。

    【2】修改第一组柱子相关形式,将bar直角变圆角

     itemStyle:{
                            barBorderRadius:20
                        }
    

    【3】修改柱子之间的距离

      name: '条',
                        type: 'bar',
                        data: [18203, 23489, 29034, 104970, 131744, 630230],
                        // 修改第一组柱子的圆角
                        itemStyle:{
                            barBorderRadius:20
                        },
                        //修改柱子间的距离
                        barCategoryGap:50,
                        //修改柱子 的宽度
                        barWidth:10,
    

     

     


    【5.4】设置第一组柱子内的百分比显示数据

     

    【1】label标签是可以在图形上显示文本的标签。

    【2】position inside 在图形内显示文字

    【3】formatter 自动将int 转化为string,即自动解析数据并显示在图表上。

    • a 系列名
    • b 数据名
    • c 数据值

     

      label:
                        {
                            show:true,
                            position:'inside',
                            // {c}会自动地解析数据,将数据转化为string显示在图表上(integer to string)
                            formatter:"{c}%",
    
    
                        }  label:
                        {
                            show:true,
                            position:'inside',
                            // {c}会自动地解析数据,将数据转化为string显示在图表上(integer to string)
                            formatter:"{c}%",
    
    
                        }
    

     


    【5.5】给柱子设置不同的颜色

    itemStyle中可以对单个柱子设置颜色。

    声明数组来定义颜色。dataindex来返回索引,然后根据索引来指定颜色。

    可以通过console.log(params)来检查。

    访问params.dataIndex即可。

     (function(){
    
            var myColor=['#1089E7','#F57474','#56D0E3','E8B448','#8B78F6'];
    
            // 1.实例化echarts对象
            var myChart= echarts.init(document.querySelector(".bar2 .chart"));
    
            // 指定配置和数据
    
           var option = {
        
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
               
                grid: {
                    left: '22%',
                    right: '0%',
                    top:'10%',
                    bottom: '10%',
                    // containLabel: true
                },
    //不显示x轴的相关信息
                xAxis: {
                    show:false,
                },
    
                yAxis: {
                    axisLine:
                    {
                        show:false
                    },
                    axisTick:
                    {
                        show:false,
                    },
    
                    axisLabel:{
                        color:"#fff",
                    },
    
    
                    type: 'category',
                    data: [ '印尼', '美国', '印度', '中国', '世界人口(万)']
                },
                series: [
                    {
                        name: '条',
                        type: 'bar',
                        data: [ 23489, 29034, 104970, 131744, 630230],
                        // 修改第一组柱子的圆角
                        itemStyle:{
                            barBorderRadius:20,
    
                            //更改每个柱子的颜色
                            color: function(params){
                                // console.log(params);
                                return myColor[params.dataIndex];
                               
    
                            }
                        },
                        //修改柱子间的距离
                        barCategoryGap:50,
                        //修改柱子 的宽度
                        barWidth:10,
                        //显示柱子内的文字
                        label:
                        {
                            show:true,
                            position:'inside',
                            // {c}会自动地解析数据,将数据转化为string显示在图表上(integer to string)
                            formatter:"{c}%",
                        }
    
                    },
    
                    {
                        name: '2012年',
                        type: 'bar',
                        data: [ 23438, 31000, 121594, 134141, 681807]
                    }
                ]
            };
    
    
            myChart.setOption(option);
        
    
        })();
    

     


    【5.6】修改第二组柱子的相关配置

     

    【1】不要柱子颜色,而要把柱子变成border边框。

      {
                        name: '框',
                        //修改柱子间的距离
                        barCategoryGap:50,
                        //修改柱子 的宽度
                        barWidth:15,
                        type: 'bar',
                        itemStyle:{
                            color:"none",
                            borderColor:'#00c1de',
                            borderWidth:3,
                            barBorderRadius:15,
                
                        },
                        data: [ 23438, 31000, 121594, 134141, 681807]
                    }
    

    【2】给第二个框框 y 轴 后面加上文字

    y axis 大括号变中括号,中括号是包含数组的,可以写两个y标度尺,跟series两个条对应起来。

    复制一份就好了。

    如果出不来的话,需要调整grid.right或者是关掉containLabel 看效果。

     yAxis:[ {
                    
                    type: 'category',
    
                    data: ["HTML5", "CSS3", "javascript", "VUE", "NODE"],
                    axisLine:
                    {
                        show:false
                    },
                    axisTick:
                    {
                        show:false,
                    },
    
                    axisLabel:{
                        color:"#fff",
                    },
                    
                }, 
    
    
                {
                    
                    type: 'category',
    
                    data:wdata,
                    axisLine:
                    {
                        show:false
                    },
                    axisTick:
                    {
                        show:false,
                    },
    
                    axisLabel:{
                        color:"#fff",
                    },
                    
                }, 
            ],
    

     


     

    【5.7】设置两组数据层叠以及更换数据

     

    【1】外框包住水平柱形图

    • series 第一个对象添加 yAxisIndex:0
    • series 第二个对象添加 yAxisIndex:1

    【2】更换数据

    • 左列名称
    • 100%数值
    • 以及其上的特定数值

     


    【5.8】翻转数据

    yaxis.inverse 是否反向数据。

    yaxis:[{
    inverse:true,
    }]
    

    可以把图表适配也给加上。

     

     

    六、折线图

     

    使用这个Stacked Line Chart 案例。

    Examples - Apache ECharts (incubating)​echarts.apache.org

    还是之前的步骤。

    【6.1】导入折线图图表

        // 三、折线图1制作
    
        (function(){
          var myChart = echarts.init(document.querySelector(".line .chart"));
    
         var  option = {
       
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
            },
                yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '邮件营销',
                    type: 'line',
                    stack: '总量',
                    data: [120, 132, 101, 134, 90, 230, 210]
                },
                {
                    name: '联盟广告',
                    type: 'line',
                    stack: '总量',
                    data: [220, 182, 191, 234, 290, 330, 310]
                },
                
            ]
        };
    
        myChart.setOption(option);
    
        window.addEventListener("resize",function(){
            myChart.resize();
        })
        })();
    

     


    【6.2】定制grid 网格

    【1】改边框

     grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                top:"20%",
                show:true,//显示边框
                borderColor:"#013f4a",//边框颜色
                containLabel: true,//包含标签在图表内
            },
            
    

     

    【2】改legend 文字颜色和位置

      legend: {
                data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎'],
                textStyle:{
                    color:"#4c9bfd"
                },
                right: "10%" , //距离右边10%
            },
    

     


    【6.3】定制x轴和y轴以及分割线相关配置

     

    x轴:

    • axisTick去除刻度线
    • axisLabel 标签文本颜色
    • axisLine 去除轴线
    • boundaryGap 去除轴内间距
      xAxis: {
                type: 'category',
                boundaryGap: false,
                data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
    
    
                axisTick:{
                    show:false,
                },
                axisLabel:{
                    color:"#4c9bfd",
                },
                axisLine:{
                    show:false,
                },
                
    
    
            },
    

     

    y轴:跟x轴一样,再复制一份就好了。

    改分割线还是用 splitLine 中的 linestyle来修改。

     yAxis: {
                type: 'value',
                boundaryGap: false,
                axisTick:{
                    show:false,
                },
                axisLabel:{
                    color:"#4c9bfd",
                },
                axisLine:{
                    show:false,
                },
    
                splitLine:{
                    lineStyle:{
                        color:"#012f4a",
                    }
                }
            },
    

     


    【6.4】定制两条折线的样式

     

    【1】定制颜色,option中添加。

      color:['#00f2f1','#ed3f35'],
    

    【2】平滑折线,在series中添加

    smooth:true,
    

     


    【6.5】数据更换

     

    更改横轴坐标信息,把星期改为12个月份。

    更改折线数据

     


    【6.6】折线图跟随年份动态变换分析

    【1】 html中添加两个链接,指向javascript脚本

      <div class="panel line">
                        <h2>
                            折线图-人员变化
                            <a href= "javascript:;"> 2020 </a>
                            <a href= "javascript:;"> 2021 </a>
                        </h2>
                        <div class="chart"></div>
                         <div class="panel-footer"></div>
                         </div>

     

    【2】定义less内容

    添加h2二号标题标签属性。

        h2{
            height:.6rem;
            color: white;
            line-height: .6rem;
            text-align: center;
            font-size: .25rem;
            font-weight: 400;
            a{
                color: #fff;
                text-decoration: underline;
                margin:0 0.125erm;
            }

     


    【6.7】定义点击行为,准备两套数据

    【1】引入jquery.js,这样才可以用$来查询(注意还是在html文档最末端引入,而且在charts.js的前面)

    然后当点击 2020/2021的字样时才会有效。

     <script src='js/flexible.js'></script>
            <script src="js/echarts.min.js"></script>
            <script src='js/jquery.js'></script>
            <script src="js/charts.js"></script>

    【2】js中写测试脚本,alert

        //5.点击切换效果
        $('.line h2').on('click','a',function(){
            alert(1);
        })
    

    【3】this指针 测试看点了哪个链接,返回当前索引

      //5.点击切换效果
        $('.line h2').on('click','a',function(){
            // alert(1);
            console.log($(this).index());
        })
    

     

    【4】返回year data

    //5.点击切换效果
        $('.line h2').on('click','a',function(){
            // alert(1);
            // console.log($(this).index());
    
            console.log(yeardata[($(this).index())]);
        })
    

     

    【5】因为series在option里面,所以我们option.series来get 数据

        //5.点击切换效果
        $('.line h2').on('click','a',function(){
            // alert(1);
            // console.log($(this).index());
    
            // console.log(yeardata[($(this).index())]);
    
            var obj=yeardata[$(this).index()];
            option.series[0].data=obj.data[0];
            option.series[1].data=obj.data[1];
            myChart.setOption(option);
        })
    

    data数据我只是更改了一下顺序。

     

    【6】更换series中的数据为 yeardata中的数据。

            series: [
                {
                    name: '新增粉丝',
                    type: 'line',
                    
                    data:  yeardata[0].data[0],
                    smooth:true,
                },
                {
                    name: '新增游客',
                    type: 'line',
                  
                   data: yeardata[0].data[1],
                    smooth:true,
                },
                
            ]
        };
    
        myChart.setOption(option);
    
        window.addEventListener("resize",function(){
            myChart.resize();
        })
    
        //5.点击切换效果
        $('.line h2').on('click','a',function(){
            // alert(1);
            // console.log($(this).index());
    
            // console.log(yeardata[($(this).index())]);
    
            var obj=yeardata[$(this).index()];
            option.series[0].data=obj.data[0];
            option.series[1].data=obj.data[1];
            //重新渲染数据
            myChart.setOption(option);
        })
    

     

    好了第一个折线图表就制作完毕了。


     

    【6.8】折线图带阴影 导入。

     

    https://echarts.apache.org/examples/zh/editor.html?c=area-stack​echarts.apache.org

    先找模板再自定义修改。

     (function(){
            var myChart=echarts.init(document.querySelector(".line2 .chart"));
    
    
           var option = {
       
                tooltip: {
                    trigger: 'axis',
                },
                
                
                legend: {
                    data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
                },
               
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        boundaryGap: false,
                        data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name: '邮件营销',
                        type: 'line',
                        stack: '总量',
                        areaStyle: {},
                        data: [120, 132, 101, 134, 90, 230, 210]
                    },
                    {
                        name: '联盟广告',
                        type: 'line',
                        stack: '总量',
                        areaStyle: {},
                        data: [220, 182, 191, 234, 290, 330, 310]
                    },
                    
                ]
            };
            
    
    
    
            myChart.setOption(option);
    
        })();
    

     


    【6.9】折线图优化

     

     

    【1】换legend文字颜色

       legend: {
                    data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎'],
                    textStyle:{
                        color:"rgba(255,255,255,.5",
                        
                    }
                },
    

     

    【2】修改图表大小

      grid: {
                    left: '10',
                    right: '10',
                    bottom: '10',
                    top:"30",
                    containLabel: true
                },

     

    【3】修改x轴

     xAxis: [
                    {
                        type: 'category',
                        boundaryGap: false,
                        data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
                        axisLabel:{
                            color:"rgba(255,255,255,.6",
    
    
                        },
                        axisLine:{
                            lineStyle:{
                               color:"rgba(255,255,255,.6",
    }
                        }
                    }
                ],
    

    【4】修改y轴

    复制x轴的

    【5】splitline alpha透明度低一点。

     

    折线图2制作
    
        (function(){
            var myChart=echarts.init(document.querySelector(".line2 .chart"));
    
    
           var option = {
       
                tooltip: {
                    trigger: 'axis',
                },
                
                
                legend: {
                    data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎'],
                    textStyle:{
                        color:"rgba(255,255,255,.5",
                        
                    }
                },
               
                grid: {
                    left: '10',
                    right: '10',
                    bottom: '10',
                    top:"30",
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        boundaryGap: false,
                        data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
                        axisLabel:{
                            color:"rgba(255,255,255,.6",
    
    
                        },
                        axisLine:{
                            lineStyle:{
                               color:"rgba(255,255,255,.6",
    }
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                       
                        boundaryGap: false,
                        data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
                        axisLabel:{
                            color:"rgba(255,255,255,.6",
    
    
                        },
                        axisLine:{
                            lineStyle:{
                               color:"rgba(255,255,255,.6",
    
    }
                        },
                        splitLine:{
                            lineStyle:{
                                color:"rgba(255,255,255,.1"
                            }
                        }
                    }
                ],
                series: [
                    {
                        name: '邮件营销',
                        type: 'line',
                        
                        areaStyle: {},
                        data: [120, 132, 101, 134, 90, 230, 210]
                    },
                    {
                        name: '联盟广告',
                        type: 'line',
                       
                        areaStyle: {},
                        data: [220, 182, 191, 234, 290, 330, 310]
                    },
                    
                ]
            };
            
    
    
    
            myChart.setOption(option);
    
        })();
    

     


    【6.10】定制填充渐变区域

     

     

    【1】smooth 圆滑

    【2】linestyle.color 改颜色 ,linestyle.width 更改线的粗细,或虚线实线

    【3】areaStyle更改 区域填充颜色

    【4】渐变色 areaStyle

    areaStyle:{
                            color:new echarts.graphic.LinearGradient(
                                0,
                                0,
                                0,
                                1,
                                [
                                    {
                                        offset:0,
                                        color:"rgba(1,132,213,0.4)",
                                    },
    
                                    {
                                        offset:0.8,
                                        color:"rgba(1,132,213,0.1)",
                                    }
    
                                ],false
                                )
                        },
    

     

    【5】Shadow Color

    shadowColor:"rgba(0,0,0,0.1)",

     

     


     

    【6.11】折线图第一个线条配置

    symbol 符号设置小拐点。

    【1】不显示小拐点

    showSymbol: false,

    【2】itemstyle 设置拐点颜色及边框(加个半透明的效果)

      itemStyle:{
                            color:"#0184d5",
                            borderColor:"rgba(221,220,107,0.1)",
                            borderWidth:12,
                        },

    【3】设置拐点样式和大小

    symbol:"circle",
                        symbolSize:8,

     


    【6.12】折线图第二个线条配置

    跟上面一样,复制一份就好了。

    【1】设置第二线条颜色渐变

    【2】更换数据

    【3】屏幕适配

     

     

     // ------------------------------------------------------------
        // 四、 折线图2制作
    
        (function(){
            var myChart=echarts.init(document.querySelector(".line2 .chart"));
    
    
           var option = {
       
                tooltip: {
                    trigger: 'axis',
                },
                
                
                legend: {
                    data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎'],
                    textStyle:{
                        color:"rgba(255,255,255,.5",
                        
                    }
                },
               
                grid: {
                    left: '10',
                    right: '10',
                    bottom: '10',
                    top:"30",
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        boundaryGap: false,
                        data: [
                            "01",
                            "02",
                            "03",
                            "04",
                            "05",
                            "06",
                            "07",
                            "08",
                            "09",
                            "11",
                            "12",
                            "13",
                            "14",
                            "15",
                            "16",
                            "17",
                            "18",
                            "19",
                            "20",
                            "21",
                            "22",
                            "23",
                            "24",
                            "25",
                            "26",
                            "27",
                            "28",
                            "29",
                            "30"
                          ],
                        axisLabel:{
                            color:"rgba(255,255,255,.6",
    
    
                        },
                        axisLine:{
                            lineStyle:{
                               color:"rgba(255,255,255,.6",
    }
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                       
                        boundaryGap: false,
                        data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
                        axisLabel:{
                            color:"rgba(255,255,255,.6",
    
    
                        },
                        axisLine:{
                            lineStyle:{
                               color:"rgba(255,255,255,.6",
    
    }
                        },
                        splitLine:{
                            lineStyle:{
                                color:"rgba(255,255,255,.1"
                            }
                        }
                    }
                ],
                series: [
                    {
                        name: '邮件营销',
                        type: 'line',
                        smooth:true,
                        
                        //单独修改当前线条的样式
                        lineStyle:{
                            color:"#0184d5",
                            width:'2',
                        },
                        areaStyle:{
                            color:new echarts.graphic.LinearGradient(
                                0,
                                0,
                                0,
                                1,
                                [
                                    {
                                        offset:0,
                                        color:"rgba(1,132,213,0.4)",
                                    },
    
                                    {
                                        offset:0.8,
                                        color:"rgba(1,132,213,0.1)",
                                    }
    
                                ],false
                                )
                        },
    
                        shadowColor:"rgba(0,0,0,0.1)",
    //设置拐点
                        symbol:"circle",
                        symbolSize:8,
                        
    
                        itemStyle:{
                            color:"#0184d5",
                            borderColor:"rgba(221,220,107,0.1)",
                            borderWidth:12,
                        },
    
                        showSymbol: false,
    
                        
                         data: [
                            30,
                            40,
                            30,
                            40,
                            30,
                            40,
                            30,
                            60,
                            20,
                            40,
                            20,
                            40,
                            30,
                            40,
                            30,
                            40,
                            30,
                            40,
                            30,
                            60,
                            20,
                            40,
                            20,
                            40,
                            30,
                            60,
                            20,
                            40,
                            20,
                            40
                          ]
                    },
    
    
    
                    {
                        name: '联盟广告',
                        type: 'line',
                        smooth:true,
    
                        lineStyle:{
                            color:"#00d887",
                            width:'2',
                        },
                        
    
                        areaStyle:{
                            color:new echarts.graphic.LinearGradient(
                                0,
                                0,
                                0,
                                1,
                                [
                                    {
                                        offset:0,
                                        color:"rgba(0,216,135,0.4)",
                                    },
    
                                    {
                                        offset:0.8,
                                        color:"rgba(0,216,135,0.1)",
                                    }
    
                                ],false
                                )
                        },
    
                        shadowColor:"rgba(0,0,0,0.1)",
    //设置拐点
                        symbol:"circle",
                        symbolSize:8,
                        
    
                        itemStyle:{
                            color:"#00d887",
                            borderColor:"rgba(221,220,107,0.1)",
                            borderWidth:12,
                        },
    
                        showSymbol: false,
    
    
    
    
                        data: [
                            50,
                            30,
                            50,
                            60,
                            10,
                            50,
                            30,
                            50,
                            60,
                            40,
                            60,
                            40,
                            80,
                            30,
                            50,
                            60,
                            10,
                            50,
                            30,
                            70,
                            20,
                            50,
                            10,
                            40,
                            50,
                            30,
                            70,
                            20,
                            50,
                            10,
                            40
                          ]
                    },
                    
                ]
            };
            
    
    
    
            myChart.setOption(option);
    
            window.addEventListener("resize",function(){
                myChart.resize();
            })
    

     


     

    七、饼形图

    【7.1】引入doughnut 饼图

     

    https://echarts.apache.org/examples/zh/editor.html?c=pie-doughnut​echarts.apache.org
    1. 实例化对象
    2. 指定配置
    3. 把配置给实例对象
    (function(){
    
        var myChart=echarts.init(document.querySelector(".pie .chart"));
    
        var option = {
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b}: {c} ({d}%)'
            },
            legend: {
                orient: 'vertical',
                left: 10,
                data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
            },
            series: [
                {
                    name: '访问来源',
                    type: 'pie',
                    radius: ['50%', '70%'],
                    avoidLabelOverlap: false,
                    label: {
                        show: false,
                        position: 'center'
                    },
                    
                    labelLine: {
                        show: false
                    },
                    data: [
                        {value: 335, name: '直接访问'},
                        {value: 310, name: '邮件营销'},
                        {value: 234, name: '联盟广告'},
                        {value: 135, name: '视频广告'},
                        {value: 1548, name: '搜索引擎'}
                    ]
                }
            ]
        };
    
        myChart.setOption(option);
        
    
    
    
    })();
    

    【7.2】定制饼形图

     

    【1】不垂直分布,删掉orient vertical。

    【2】left 改为 bottom,0

    【3】修改小图标的宽度和高度,用itemWidth/Height 来调节。

     legend: {
                
                bottom: 0,
                itemWidth:10,
                itemHeight:10,
                data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
            },
    

    【4】修改legend 文字样式,用text style

     


    【7.3】修改饼形图的大小

     

     

    用radius 来修改图形大小,内圆和外圆。

    radius:['内径','外径’]

    label显示图形上的文字,labelline 链接文字和图形的线。


    【7.4】修改数据

     

     

    value 影响饼图占比。

    color 更改饼图颜色,放在option 中。

    center 修改圆的圆心位置

    最后别忘了屏幕适配。


    【7.5】引入南丁格尔玫瑰图

    Examples - Apache ECharts (incubating)​echarts.apache.org
    // 六、南丁格尔玫瑰图制作
    (function(){
        var myChart =echarts.init(document.querySelector(".pie2 .chart"));
    
        option = {
            
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b} : {c} ({d}%)'
            },
            legend: {
                left: 'center',
                top: 'bottom',
                data: ['rose1', 'rose2', 'rose3', 'rose4', 'rose5', 'rose6', 'rose7', 'rose8']
            },
           
            series: [
              
                {
                    name: '面积模式',
                    type: 'pie',
                    radius: [30, 110],
                    center: ['75%', '50%'],
                    roseType: 'area',
                    data: [
                        {value: 10, name: 'rose1'},
                        {value: 5, name: 'rose2'},
                        {value: 15, name: 'rose3'},
                        {value: 25, name: 'rose4'},
                        {value: 20, name: 'rose5'},
                        {value: 35, name: 'rose6'},
                        {value: 30, name: 'rose7'},
                        {value: 40, name: 'rose8'}
                    ]
                }
            ]
        };
    
        
        myChart.setOption(option);
    
        window.addEventListener("resize",function(){
            myChart.resize();
        })
    
    })();
    

     

     


    【7.6】定制玫瑰图上

    【1】设置颜色

    【2】修改大小 radius

    【3】把饼形图的显示模式改为 半径模式

    roseType:‘radius’,

    【4】数据更换

     

    // 六、南丁格尔玫瑰图制作
    (function(){
        var myChart =echarts.init(document.querySelector(".pie2 .chart"));
    
        option = {
    
            color: [
                "#006cff",
                "#60cda0",
                "#ed8884",
                "#ff9f7f",
                "#0096ff",
                "#9fe6b8",
                "#32c5e9",
                "#1d9dff"
              ],
            
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b} : {c} ({d}%)'
            },
            legend: {
                left: 'center',
                top: 'bottom',
                data: ['rose1', 'rose2', 'rose3', 'rose4', 'rose5', 'rose6', 'rose7', 'rose8']
            },
           
            series: [
              
                {
                    name: '地区分布',
                    type: 'pie',
                    radius: [10, 70],
                    center: ['50%', '50%'],
                    roseType: 'radius',
                    data: [
                        { value: 20, name: "云南" },
                        { value: 26, name: "北京" },
                        { value: 24, name: "山东" },
                        { value: 25, name: "河北" },
                        { value: 20, name: "江苏" },
                        { value: 25, name: "浙江" },
                        { value: 30, name: "深圳" },
                        { value: 42, name: "广东" }
                      ],
                }
            ]
        };
    
        
        myChart.setOption(option);
    
        window.addEventListener("resize",function(){
            myChart.resize();
        })
    
    })();
    

     


    【7.7】定制玫瑰图下

     

    【1】修改文字大小 通过label 修改

    【2】修改线条(视觉引导线)粗细 labelline修改

    length 链接图形,length2链接文字。

    【3】修改图例legend 大小位置、文字颜色

     

    // 六、南丁格尔玫瑰图制作
    
    (function(){
        var myChart =echarts.init(document.querySelector(".pie2 .chart"));
    
        option = {
    
            color: [
                "#006cff",
                "#60cda0",
                "#ed8884",
                "#ff9f7f",
                "#0096ff",
                "#9fe6b8",
                "#32c5e9",
                "#1d9dff"
              ],
            
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b} : {c} ({d}%)'
            },
            legend: {
                
                bottom: 0,
                itemWidth:10,
                itemHeight:10,
                textStyle:{
                    color:"rgba(255,255,255,.5)",
    
                },
    
            },
           
            series: [
              
                {
                    name: '地区分布',
                    type: 'pie',
                    radius: [10, 70],
                    center: ['50%', '50%'],
    
                    label:{
                        fontSize:10,
                    },
    
                    labelLine:{
                        length:6,
                        length2:8,
                    },
                    roseType: 'radius',
                    data: [
                        { value: 20, name: "云南" },
                        { value: 26, name: "北京" },
                        { value: 24, name: "山东" },
                        { value: 25, name: "河北" },
                        { value: 20, name: "江苏" },
                        { value: 25, name: "浙江" },
                        { value: 30, name: "深圳" },
                        { value: 42, name: "广东" }
                      ],
                }
            ]
        };
    
        
        myChart.setOption(option);
    
        window.addEventListener("resize",function(){
            myChart.resize();
        })
    
    })();
    

     

     

     

    八、中国地图

     

     

    【8.1】从社区中获取引入中国地图模块

     

     

    使用这个航线地图。

    ECharts Gallery​gallery.echartsjs.com

    geoCoordMap 是各城市的经纬度。

    我们需要使用china.js文件来显示中国地图

    【1】 引入china.js文件

    【2】跟之前一样

    如果出现这种中国地图加载不出来的情况,就检查,或者是替换为源文件,进行compare对比。

     

    最后我发现是这里china.js 后面多了一个小括号,我找了好长时间哪,哎,排查了各种原因,javascript、Css的。

     


    【8.2】定制中国地图

     

    【1】去掉option中的 title和背景颜色。

    【2】geo 中的item style.areaColor 改省份颜色

    border color改颜色,十六进制变rbgb。

    【3】geo中zoom放大中国地图


    【8.3】约束屏幕缩放

    //................................................
    @media screen and (max-width: 1024px) {
      html {
        font-size: 42px !important;
      }
    }
    @media screen and (min-width: 1920) {
      html {
        font-size: 80px !important;
      }
    }
    

    overflow:hidden隐藏滚动条。

     
  • 相关阅读:
    《大道至简》读后感
    第一周学习总结-Java
    c++与java的几个不同点
    单调队列 滑动窗口模型
    计算空间
    关于dp初始化问题
    康托展开小结-
    Vm-Ubuntu下配置Qt开发环境
    C++学习013多态
    C++学习012友元
  • 原文地址:https://www.cnblogs.com/xinxihua/p/14327781.html
Copyright © 2011-2022 走看看