百度echarts交流群 QQ群号796689882 - Go语言中文社区

百度echarts交流群 QQ群号796689882


不知道为什么腾讯不允许echarts群,我只能建一个群了

百度echarts交流群 QQ群号796689882

  1. <code class="language-javascript"><!DOCTYPE html>  
  2. <html>  
  3.     <head>  
  4.         <meta charset="UTF-8">  
  5.         <title>折线图案例</title>  
  6.         <!-- 引入 ECharts 文件 -->  
  7.         <script src="js/echarts4.0.js" type="text/javascript" charset="utf-8"></script>  
  8.     </head>  
  9.     <body>  
  10.         <!-- 为 ECharts 准备一个具备大小(宽高)的 容器 -->  
  11.         <div id="chart1" style="width: 80%;height: 400px;top: 50px;left: 10%;border: 3px solid #FF0000;"></div>  
  12.     </body>  
  13. </html>  
  14. <script type="text/javascript">  
  15.     // 基于准备好的容器(这里的容器是id为chart1的div),初始化echarts实例  
  16.     var chart1 = echarts.init(document.getElementById("chart1"));  
  17.       
  18.     // 指定图表的配置项和数据  
  19.     var dataX = ['18~30岁', '31~40岁', '41~50岁', '51~60岁', '61~70岁'];  
  20.     var dataY = ['200', '102', '422', '189', '12'];  
  21.     var dataZ = [500, 500, 500, 500, 500];  
  22.     var option = {  
  23.         title: {  
  24.             text: '折线图标题',  
  25.             link: 'https://blog.csdn.net/gray_key',  
  26.             target: 'blank',  
  27.             left: '5%',  
  28.             textStyle: {  
  29.                 color: '#fff',  
  30.                 fontSize: 15,  
  31.                 bottom: 20  
  32.             }  
  33.         },  
  34.         grid: {  
  35.             left: 40,  
  36.             right: 40,  
  37.             top: 30,  
  38.             bottom: 25,  
  39.         },  
  40.         backgroundColor: 'rgba(0,0,0,0.8)',     // 背景颜色  
  41.         tooltip: {  
  42.             trigger: 'item',  
  43.             formatter: "{a}<br/>{b} : {c}人"  
  44.         },  
  45.         xAxis: {  
  46.             type: 'category',  
  47.             position: 'bottom',  
  48.             // 等同于 axisLine: true    开始  
  49.             axisLine: {  
  50.                 show: false  
  51.             },  
  52.             axisTick: {  
  53.                 show: false  
  54.             },  
  55.             // 等同于 axisLine: true    结束  
  56.             axisLabel: {  
  57.                 color: '#fff',  
  58.                 fontSize: 12  
  59.             },  
  60.             data: dataX,  
  61.         },  
  62.         yAxis: {  
  63.             splitNumber: 5, // 坐标轴的分割段数,需要注意的是这个分割段数只是个预估值,最后实际显示的段数会在这个基础上根据分割后坐标轴刻度显示的易读程度作调整。在类目轴中无效。  
  64.             // 等同于 axisLine: true    开始  
  65.             axisLine: {  
  66.                 show: false  
  67.             },  
  68.             axisTick: {  
  69.                 show: false  
  70.             },  
  71.             // 等同于 axisLine: true    结束  
  72.             splitLine: {  
  73.                 show: true,  
  74.                 lineStyle: {  
  75.                     color: '#fff',  
  76.                     opacity: 0.2  
  77.                 }  
  78.             },  
  79.             axisLabel: {  
  80.                 color: '#fff',  
  81.                 fontSize: 12  
  82.             }  
  83.         },  
  84.         series: [{  
  85.             name: '各年龄段人数',  
  86.             type: 'line',  
  87.             data: dataY,  
  88.             smooth: true,  
  89.             symbol: 'emptyCircle',  
  90.             symbolSize: 5,  
  91.             itemStyle: {  
  92.                 normal: {  
  93.                     color: '#fff'  
  94.                 }  
  95.             },  
  96.             lineStyle: {  
  97.                 normal: {  
  98.                     color: {  
  99.                         type: 'linear',  
  100.                         x: 0,  
  101.                         y: 0,  
  102.                         x2: 0,  
  103.                         y2: 1,  
  104.                         colorStops: [{  
  105.                             offset: 0, color: 'rgba(255,0,0,0.8)' // 0% 处的颜色  
  106.                         }, {  
  107.                             offset: 1, color: 'rgba(0,0,238,0.8)' // 100% 处的颜色  
  108.                         }],  
  109.                         globalCoord: false // 缺省为 false  
  110.                     },  
  111.                     width: 3  
  112.                 }  
  113.             },  
  114.             areaStyle: {  
  115.                 normal: {  
  116.                     color: "rgba(51,255,255,0.3)",  
  117.                 }  
  118.             },  
  119.             markLine: { // 图表标线。  
  120.                 silent: false, // 图形是否不响应和触发鼠标事件,默认为 false,即响应和触发鼠标事件。  
  121.                 symbol: ["", "arrow"], // 标线两端的标记类型,可以是一个数组分别指定两端,也可以是单个统一指定,具体格式见 data.symbol。  
  122.                 // 标线的数据数组。每个数组项可以是一个两个值的数组,分别表示线的起点和终点,每一项是一个对象,有下面几种方式指定起点或终点的位置。  
  123.                 data: [{ // 直接用 type 属性标注系列中的最大值,最小值。这时候可以使用 valueIndex 或者 valueDim 指定是在哪个维度上的最大值、最小值、平均值。   
  124.                     name: '平均数',  
  125.                     type: 'average' // 支持 'average', 'min', 'max'  
  126.                 }],  
  127.                 precision: 0, // 标线数值的精度,在显示平均值线的时候有用。  
  128.                 label: { // 标线的文本。  
  129.                     normal: {  
  130.                         formatter: '平均数:n{c}人'  
  131.                     }  
  132.                 },  
  133.                 lineStyle: { // 标线的样式    
  134.                     normal: {  
  135.                         color: '#fff',  
  136.                     }  
  137.                 }  
  138.             }  
  139.         }, {  
  140.             name: '占位背景',  
  141.             type: 'bar',  
  142.             itemStyle: {  
  143.                 normal: {  
  144.                     show: true,  
  145.                     color: '#fff',  
  146.                     opacity: 0  
  147.                 }  
  148.             },  
  149.             silent: true, // 图形是否不响应和触发鼠标事件,默认为 false,即响应和触发鼠标事件。  
  150.             barWidth: '50%', // 柱条宽度  
  151.             data: dataZ, // 占位背景在y轴上的值(高度)  
  152.             animation: false // 是否开启动画  
  153.         }, {  
  154.             name: '占位背景',  
  155.             type: 'bar',  
  156.             itemStyle: {  
  157.                 normal: {  
  158.                     show: true,  
  159.                     color: '#fff',  
  160.                     opacity: 0.1  
  161.                 }  
  162.             },  
  163.             silent: true,  
  164.             barWidth: '50%',  
  165.             barGap: 0, // 柱间距离  
  166.             data: dataZ,  
  167.             animation: false  
  168.         }],  
  169.     };  
  170.       
  171.     // 使用刚指定的配置项和数据显示图表  
  172.     chart1.setOption(option)  
  173. </script></code>  
版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_33026699/article/details/82217551
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-06-28 03:45:48
  • 阅读 ( 1386 )
  • 分类:职场

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢