Echarts.js简介

在平时开发项目时,免不了需要对数据进行图表显示的需求,比如:趋势图、饼状图、柱形图等。
Echarts.js是来自百度团队研发的图表js插件,利用HTML+js实现折线图、饼状图、热点图、3d图形等等,可在PC和移动端显示,加载速度快,功能丰富。

一、Echart官网首页

https://echarts.apache.org/zh/index.html
官网首页有着很多实例以及相关介绍,获取echart.js可以从本人百度网盘获取,包含所有图表组件,可直接引用。

链接:https://pan.baidu.com/s/1IEm8NGwqq4ExgYWp8mz9CA
提取码:aihy

二、Echart Demo已亲测,可直接使用

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <!-- 引入 ECharts 文件 -->
  <script src="echarts.min.js"></script>
</head>
</html>

为Echarts放置一个具备宽高的DOM容器

<div id="main" style="width:100%; height:600px; margin:80px 0 80px 0;"></div>   

Echarts加载数据

<script type="text/javascript"> 
              // 基于准备好的dom,初始化echarts实例
              var myChart = echarts.init(document.getElementById('main'));
              // 指定图表的配置项和数据
              var option = {
                backgroundColor: '#2c343c',
      
          title: {
              text: 'Customized Pie',     
              left: 'center',     
              top: 20,    
              textStyle: {    
                  color: '#ccc'   
              }   
          },              
          tooltip : {
      
              trigger: 'item',
      
              formatter: "{a} <br/>{b} : {c} ({d}%)"  
          },                  
          visualMap: {        
              show: false,    
              min: 80,    
              max: 600,   
              inRange: {  
                  colorLightness: [0, 1]
              }
          },  
          series : [  
              {   
                  name:'访问来源',    
                  type:'pie',
                  radius : '55%', 
                  center: ['50%', '50%'], 
                  data:[  
                      {value:335, name:'直接访问'},
      
                      {value:310, name:'邮件营销'},
      
                      {value:274, name:'联盟广告'},
      
                      {value:235, name:'视频广告'},
      
                      {value:400, name:'搜索引擎'}
      
                  ].sort(function (a, b) { return a.value - b.value; }),      
                  roseType: 'radius', 
                  label: {    
                      normal: {   
                          textStyle: {    
                              color: 'rgba(255, 255, 255, 0.3)'   
                          }   
                      }       
                  },  
                  labelLine: {        
                      normal: {       
                          lineStyle: {        
                              color: 'rgba(255, 255, 255, 0.3)'       
                          },      
                          smooth: 0.2,        
                          length: 10,     
                          length2: 20     
                      }       
                  },      
                  itemStyle: {        
                      normal: {       
                          color: '#c23531',       
                          shadowBlur: 200,        
                          shadowColor: 'rgba(0, 0, 0, 0.5)'       
                      }   
                  },              
                  animationType: 'scale',     
                  animationEasing: 'elasticOut',      
                  animationDelay: function (idx) {        
                      return Math.random() * 200;
      
                  }       
              }       
          ]       
              };      
              // 使用刚指定的配置项和数据显示图表。        
              myChart.setOption(option);      
       </script>

三、数据展示

1599233262(1).jpg
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容