echarts常用实例
1、柱状图:
1、需要动态加载的参数是x轴以及柱状图的数值,legendData和seriesData。demo使用是可以直接写死参数,在执行this.initChart()方法即可。具体代码可以参数以下code.
<!--门禁卡开门统计--> <template><div class="openCardCountEle" style="height: 90%;width: 100%;padding: 4px;" v-loading="isLoading"><div style="width: 100%;height: 100%;z-index: 0"><div id="openCardCountEleID"></div></div></div> </template><script>import echarts from 'echarts';import {getFileDetail30DaysTime} from 'api/viasadmin/arcgisMap/IntelDigCtrl';import {openCardCount} from 'api/dashboard';export default {name: "openCardCountEle",props:['curDAItem'],data() {return {chart: null,id: 'openCardCountEleID',isLoading: false,color: ['#ff8463','#9bca62','#2ec7c9','#b6a2de','#5ab1ef','#8d98b3','#e5cf0d','#97b552','#95706d','#dc69aa','#07a2a4','#9a7fd1','#588dd5','#f5994e','#c05050','#59678c','#c9ab00','#7eb00a','#6f5553','#c14089'],legendData: ['0:00-2:00', '2:00-4:00', '4:00-6:00', '6:00-8:00', '8:00-10:00', '10:00-12:00','12:00-14:00','14:00-16:00','16:00-18:00','18:00-20:00','20:00-22:00','22:00-24:00'],seriesData:[],// seriesData:[10, 52, 200, 334, 390, 330, 220], };},beforeDestroy() {if (!this.chart) {return false;}this.chart.dispose();this.chart = null;},beforeCreate(){},created(){},mounted() {this.$nextTick(() => {this.getList();// this.initChart(); });},methods: {getList(){//获取上次的勾选记录this.isLoading = true;const param ={archivesCode:this.curDAItem.archivesCode,topNum:10}getFileDetail30DaysTime(param).then(rsp=>{this.isLoading = false;if(rsp.status == 200 && rsp.data){this.seriesData = rsp.data;} else {this.seriesData =[];}this.initChart();})},initChart() {$("#openCardCountEleID").width($(".openCardCountEle").width());$("#openCardCountEleID").height($(".openCardCountEle").height());this.chart = echarts.init(document.getElementById(this.id));this.chart.setOption({color: this.color,grid: {left: '80px',right: '50px',top: '70px',bottom:'30px',},legend: {data: ['感知次数'],top: 20,textStyle:{color:'#E69142', fontWeight:'bold'},},title: {text: '设备感知次数',textStyle:{fontSize: 16,fontWeight: "normal",color: "#32DBEF"}},tooltip: {trigger: 'axis',showDelay:200,},xAxis: {type: 'category',data: this.legendData,axisLine: {lineStyle: {color: '#fff',width: 1,//这里是为了突出显示加上的 },},splitLine: {show: false,lineStyle:{color: ['#2E65B1'], width: 1, type: 'solid'}}},yAxis : [{axisLine: {lineStyle: {color: '#fff', width: 1}},type : 'value',splitLine: {show: true, lineStyle:{color: ['#2E65B1'], width: 1, type: 'solid'}},axisLabel: {show: true, textStyle: {color: '#fff'}}}],series : [{name:'感知次数',type:'bar',data:this.seriesData,barMaxWidth: '30',itemStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{offset: 0,color: "#FFCF68" // 0% 处的颜色 },{offset: 0.5,color: "#ff9333" // 100% 处的颜色 }, {offset: 1,color: "#ff9333" // 100% 处的颜色}], false)}}}]},true);}}} </script><style scoped></style>
View Code
2、折现图。折线过多,legend需要支持分页。
数据接口格式:
<!--视频门禁--> <template><div class="videoDoorCtrl" v-loading="isLoading"><div class="videoDoorTitle"><span class="title">视频门禁进出数据统计</span><span class="mapSelectBox"><el-select class="selectCls" v-model="regionTypeVal" multiple collapse-tags @change="outInTypeChange"><el-option v-for="item in AreaOptionList" :key="item.value" :label="item.label" :value="item.value"> </el-option></el-select></span></div><div style="width: 100%;height: 100%;z-index: 0"><div :class="className" id="videoDoorID"></div></div></div> </template><script>import echarts from 'echarts';import {doorCount} from 'api/viasadmin/arcgisMap/arcgisMap';import {residentialAreaDoorList} from '../../../api/com';export default {name: "videoDoorCtrl",props: {className: { type: String, default: 'chart'},id: { type: String, default: 'videoDoorID' },},data() {return {chart: null,regionTypeVal:[],outInTypeOpt:[{value:'1',label:'出门'},{value:'2',label:'入门'}],isLoading:false,color:['#ff8463','#9bca62','#2ec7c9','#b6a2de','#5ab1ef','#8d98b3','#e5cf0d','#97b552','#95706d','#dc69aa','#07a2a4','#9a7fd1','#588dd5','#f5994e','#c05050','#59678c','#c9ab00','#7eb00a','#6f5553','#c14089'],legendData:[],seriesData:[],selected:{},AreaOptionList:[],param : {esList:[], // 空的话默认查询全部startDate:'', // 默认当天endDate:''}};},beforeDestroy() {if (!this.chart) {return false;}this.chart.dispose();this.chart = null;},beforeCreate(){},created(){this.getAreaList();},methods: {getAreaList(){const paramList = {};let getLastSet=[];if(window.localStorage.getItem("mapHomeVideoDoorSelectList")){getLastSet = JSON.parse(window.localStorage.getItem("mapHomeVideoDoorSelectList"));}//获取上次的勾选记录this.isLoading = true;residentialAreaDoorList(paramList).then(rsp =>{this.isLoading = false;if(rsp.status == 200){for(let i = 0;i<rsp.result.length;i++){this.AreaOptionList.push({'value': rsp.result[i].value, 'label': rsp.result[i].label});}if(getLastSet){for(let i =0;i<getLastSet.length;i++){this.regionTypeVal.push(getLastSet[i].id);this.param.esList.push({id:getLastSet[i].id})}}} else {this.AreaOptionList = [];}this.getChartData();})},getChartData(){doorCount(this.param).then(rsp => {this.legendData = [];this.seriesData= [];this.selected= [];if (rsp.status == 200) {for (let i = 0; i < rsp.data.list.length; i++) {this.legendData.push(rsp.data.list[i].esName);this.seriesData.push({name: rsp.data.list[i].esName,type: 'line',stack: '总量',data: rsp.data.list[i].list})this.selected[rsp.data.list[i].esName] = i;}} else{this.seriesData = [];this.legendData = [];this.selected = {};}this.initChart();})},initChart() {// $("#videoDoorID").width($(".videoDoorCtrl").width());// $("#videoDoorID").height($(".videoDoorCtrl").height());$("#videoDoorID").width($(window).width() * 0.20); // 和首页的initPage方法进行对应。$("#videoDoorID").height(($(window).height()-80)*0.25);this.chart = echarts.init(document.getElementById(this.id));this.chart.setOption({color: this.color,grid: {left: '50px',right: '30px',top: '50px',bottom:'80px'},legend: {type: 'scroll',orient: 'horizontal',//verticalright: 10,bottom: 20,data: this.legendData,textStyle:{color:'#E69142',fontWeight:'bold'},pageTextStyle:{ //图例页信息的文字样式。color:'#fff'},animation:true,selected: this.selected,pageIconColor: '#00FFFF', //翻页按钮的颜色。pageIconInactiveColor:'#ADE5E5', // 翻页按钮不激活时(即翻页到头时)的颜色 },tooltip: {trigger: 'axis',axisPointer: {type: 'line'},showDelay:200,confine :true, //是否将 tooltip 框限制在图表的区域内 },xAxis: {type: 'category',boundaryGap: false,data: ['0','1:00','2:00','3:00','4:00','5:00','6:00','7:00','8:00','9:00','10:00','11:00','12:00', '13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00','24:00'],axisLine: {lineStyle: {color: '#fff',width: 1,//这里是为了突出显示加上的 }},splitLine: {show: false,lineStyle:{color: ['#666'], width: 1, type: 'solid'}}},yAxis: {type: 'value',axisLine: {lineStyle: {color: '#fff', width: 1}},splitLine: {show: true,lineStyle:{color: ['#666'], width: 1, type: 'solid'}},axisLabel: {show: true, textStyle: {color: '#fff'}}},series: this.seriesData},true);},outInTypeChange(val){this.regionTypeVal = val;this.param.esList = [];for(let i = 0;i<this.regionTypeVal.length;i++){this.param.esList.push({id:this.regionTypeVal[i]});}// 把勾选的结果保存到localstroagewindow.localStorage.setItem("mapHomeVideoDoorSelectList",JSON.stringify(this.param.esList));this.getChartData();}}} </script><style scoped>.videoDoorCtrl {color: #333;padding: 5px;width: 100%;height: 100%;position: relative;}.videoDoorTitle {position: absolute;top: 5px;z-index: 9;width: 100%;}.selectCls {width: 50%;border-radius: 6px;float: right;margin-right: 10px;}.videoDoorTitle .title{color: #ffffff;font-weight: 600;/*font-size: 15px;*/font-size: 0.18rem;margin-top: 8px;display: inline-block;}</style>
View Code
3、饼状图。
此处是2个冰柱图进行轮播,没有截图出图二。
数据格式如下:
1 <!--辖区基础数据--> 2 <template> 3 <div style="margin: 2%;height: 100%;width: 100%;" class="communityPolice"> 4 <el-carousel height="100%" :autoplay=false :interval = 1000*30> 5 <el-carousel-item> 6 <el-col :span="4"> 7 <span style="display: inline-block;text-align: center;width: 100%;">今日告警<br/>总数:</span> 8 <span class="totalCls"> 9 {{policeData.totalCount}} 10 </span> 11 </el-col> 12 <el-col :span="20"> 13 <div class="chartsOutter" style="width: 98%;height: 100%;"> 14 <div id="policID" style="width: 100%;"></div> 15 </div> 16 </el-col> 17 </el-carousel-item> 18 <el-carousel-item> 19 <el-col :span="4"> 20 <span style="display: inline-block;text-align: center;width: 100%;">警情总数:</span> 21 <span class="totalCls"> 22 {{warnDetilData.totalCount}} 23 </span> 24 </el-col> 25 <el-col :span="20"> 26 <div class="chartsOutter" style="width: 98%;height: 100%;"> 27 <div id="warnDetilID" style="width: 100%;"></div> 28 </div> 29 </el-col> 30 </el-carousel-item> 31 </el-carousel> 32 </div> 33 </template> 34 35 <script> 36 import {communityCount,communityXQCount,communityXQWarnCount} from 'api/viasadmin/arcgisMap/arcgisMap'; 37 import {filterFieldFun,curTimeFun} from 'filters/index'; 38 import { mapGetters } from 'vuex'; 39 import echarts from 'echarts'; 40 41 export default { 42 name: "communityPolice", 43 data() { 44 return { 45 esListParam:[], 46 color:[ 47 '#3CA45C','#EB6F13','#C9C438','#5BB7EC','#D882C3', 48 '#8d98b3','#e5cf0d','#97b552','#95706d','#dc69aa', 49 '#07a2a4','#9a7fd1','#588dd5','#f5994e','#c05050', 50 '#59678c','#c9ab00','#7eb00a','#6f5553','#c14089' 51 ], 52 listQueryWarn:{ 53 startTime:'', 54 endTime:'', 55 esList:[] 56 }, 57 warnDetilData:{ 58 totalCount:'', 59 seriesData:[], 60 legendData:[], 61 }, 62 listQueryPolice:{ 63 endDate:'', 64 startDate:'', 65 esList:[] 66 }, 67 policeData:{ 68 totalCount:'', 69 seriesData:[], 70 legendData:[], 71 } 72 } 73 }, 74 computed: { 75 ...mapGetters([ 'mapGlobalCommunityIDGetter']) 76 }, 77 watch: { 78 // 监听所选社区数据变化 79 mapGlobalCommunityIDGetter(val) { 80 this.listQueryPolice.esList = val; 81 this.getPoliceChartData(); 82 }, 83 }, 84 created() { 85 let timeTodayStart = curTimeFun('1','-')+' 00:00:00'; 86 let timeTodayEnd = curTimeFun('1','-')+' 23:59:59'; 87 this.listQueryPolice.startDate = timeTodayStart; 88 this.listQueryPolice.endDate = timeTodayEnd; 89 this.listQueryWarn.startTime = timeTodayStart; 90 this.listQueryWarn.endTime = timeTodayEnd; 91 }, 92 mounted() { 93 this.$nextTick(() => { 94 this.listQueryPolice.esList = this.$store.getters.mapGlobalCommunityIDGetter; 95 this.getPoliceChartData(); 96 this.getWarnDetilChartData(); 97 }); 98 }, 99 methods: { 100 getWarnDetilChartData(){ // 警情总数 101 communityXQWarnCount(this.listQueryWarn).then(rsp=>{ 102 if(rsp.status == 200){ 103 let total= 0; 104 this.warnDetilData.legendData = []; 105 this.warnDetilData.seriesData = []; 106 for(let i = 0;i<rsp.data.length;i++){ 107 total +=rsp.data[i].policeCaseNum; 108 this.warnDetilData.legendData.push(rsp.data[i].policeCaseType); 109 this.warnDetilData.seriesData.push({ 110 value:rsp.data[i].policeCaseNum, 111 name:rsp.data[i].policeCaseType 112 }) 113 } 114 this.warnDetilData.totalCount = total; 115 this.initWainDetilChart(); 116 } 117 }) 118 }, 119 initWainDetilChart() { // 警情总数 120 $("#warnDetilID").width($(window).width() * 0.20*0.9); // 和首页的initPage方法进行对应。 121 $("#warnDetilID").height(($(window).height()-80)*0.13); 122 this.chart = echarts.init(document.getElementById("warnDetilID")); 123 this.chart.setOption({ 124 color: this.color, 125 tooltip : {trigger: 'item', formatter: "{a} <br/>{b} : {c} ({d}%)"}, 126 grid: {top: '0px', bottom:'80px', right:'10px'}, 127 legend: { 128 orient: 'vertical', 129 type: 'scroll', 130 left: 'right', 131 icon:'circle', 132 right: 30, 133 pageTextStyle:{color:'#fff'}, //图例页信息的文字样式。 134 textStyle:{color:'#fff',}, 135 animation:true, 136 data: this.warnDetilData.legendData, 137 selected: this.policeData.legendData, 138 pageIconColor: '#00FFFF', //翻页按钮的颜色。 139 pageIconInactiveColor:'#ADE5E5', // 翻页按钮不激活时(即翻页到头时)的颜色 140 }, 141 series : [{ 142 name: '警情总数', 143 type: 'pie', 144 radius : '38%', 145 center: ['35%', '40%'], 146 data: this.warnDetilData.seriesData, 147 itemStyle: {emphasis: {shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)'}}, 148 label:{ 149 normal:{ 150 formatter: "{b}({c}个)" 151 } 152 } 153 }] 154 },true); 155 }, 156 getPoliceChartData(){ // 警情告警 157 communityXQCount(this.listQueryPolice).then(rsp=>{ 158 if(rsp.status == 200){ 159 this.policeData.totalCount = rsp.data.totalCount; 160 this.policeData.legendData = []; 161 this.policeData.seriesData = []; 162 for(let i = 0;i<rsp.data.list.length;i++){ 163 this.policeData.legendData.push(filterFieldFun(rsp.data.list[i].alarmType,'alarmTypeGetter')); 164 this.policeData.seriesData.push({ 165 value:rsp.data.list[i].alarmCount, 166 name:filterFieldFun(rsp.data.list[i].alarmType,'alarmTypeGetter') 167 }) 168 } 169 this.initPolicChart(); 170 } 171 }) 172 }, 173 initPolicChart() { // 今日告警 174 175 $("#policID").width($(window).width() * 0.20*0.9); // 和首页的initPage方法进行对应。 176 $("#policID").height(($(window).height()-80)*0.13); 177 this.chart = echarts.init(document.getElementById("policID")); 178 this.chart.setOption({ 179 color: this.color, 180 tooltip : {trigger: 'item', formatter: "{a} <br/>{b} : {c} ({d}%)"}, 181 grid: {top: '0px', bottom:'80px', right:'10px'}, 182 legend: { 183 type: 'scroll', 184 orient: 'vertical', 185 icon:'circle', 186 left: 'right', 187 right: 30, 188 pageTextStyle:{color:'#fff'}, //图例页信息的文字样式。 189 textStyle:{color:'#fff',}, 190 animation:true, 191 data: this.policeData.legendData, 192 selected: this.policeData.legendData, 193 pageIconColor: '#00FFFF', //翻页按钮的颜色。 194 pageIconInactiveColor:'#ADE5E5', // 翻页按钮不激活时(即翻页到头时)的颜色 195 }, 196 series : [{ 197 name: '今日告警总数', 198 type: 'pie', 199 radius : '38%', 200 center: ['35%', '40%'], 201 data: this.policeData.seriesData, 202 itemStyle: {emphasis: {shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)'}}, 203 label:{ 204 normal:{ 205 formatter: "{b}({c}个)" 206 } 207 } 208 }] 209 },true); 210 }, 211 }, 212 } 213 </script> 214 215 <style rel="stylesheet/scss" lang="scss" scoped> 216 .el-col {217 height: 100%; 218 } 219 .communityPolice td {220 padding: 8px; 221 } 222 .communityPolice .tdnum {223 color: #ff9333; 224 font-weight: 600 225 } 226 .communityPolice .totalCls {227 display: inline-block; 228 text-align: center; 229 width: 100%; 230 font-size: 16px; 231 font-weight: 600; 232 background: #1b3a74; 233 border-radius: 100%; 234 height: 30px; 235 color: yellow; 236 line-height: 30px; 237 margin-top: 10px; 238 } 239 </style>
View Code
转载于:https://www.cnblogs.com/luoxuemei/p/10716046.html
echarts常用实例相关推荐
- ECharts常用配置项
ECharts常用配置 setOption()绘制图表 使用 echarts 实例的 setOption() 可以设置图表实例的配置项以及数据,万能接口,所有参数和数据的修改都可以通过 setOpti ...
- Vue学习(常用实例、脚手架搭建)-学习笔记
文章目录 Vue学习(常用实例.脚手架搭建)-学习笔记 实例1 法1 法2 实例2 脚手架搭建 vue-cli2.0 vue-cli4.0 Vue学习(常用实例.脚手架搭建)-学习笔记 附加:阿里巴巴 ...
- 24种常用HTML常用实例
介绍: HTML常用实例提供24种常用样式 网盘下载地址: http://kekewangLuo.net/M9C9FL7EwjU0 图片:
- ECharts 常用图表一看即会「散点图」「饼图」「地图」「雷达图」「仪表盘」
文接上篇 ECharts 入门知识 ECharts 入门真的很简单 ,本文继续介绍 ECharts 常用图表相关内容. 一.散点图 散点图多用于推断不同维度数据之间的相关性,如下图判断身高体重相关性散 ...
- 【转】 Android常用实例—Alert Dialog的使用
Android常用实例-Alert Dialog的使用 AlertDialog的使用很普遍,在应用中当你想要用户做出"是"或"否"或者其它各式各样的选择时,为了 ...
- Apache Echarts常用图表之柱状图
文章目录 Echarts常用图表 柱状图 1. 柱状图的实现步骤 2. 柱状图的常见效果 最大值\最小值 `markPoint` 平均值 `markLine` 数值显示 `label` 柱宽度 `ba ...
- ECharts饼图实例
ECharts饼图实例 1.引入jQuery的js文件 2.引入echarts的js文件 test.html页面 <!DOCTYPE html PUBLIC "-//W3C//DTD ...
- JavaScript 常用实例
阅读目录 阐述 JavaScript 常用实例 字符串操作 去除字符串空格 字母大小写切换 字符串循环复制 字符串替换 替换 * 检测字符串 检测密码强度 随机码(toString详解) 查找字符串次 ...
- Android常用实例——截取APP当前界面(可带图片、文字水印)
Android常用实例--截取APP当前界面(可带图片.文字水印) 标签: android界面截图保存图片 2016-08-16 10:52 1262人阅读 评论(2) 收藏 举报 分类: Andr ...
最新文章
- 1048 Find Coins(二分法解法)
- python加号换行,Python字符串拼接六种方法介绍
- Juyter notebook 出现“localhost 目前无法处理此请求”
- 面试题之在字符串中查找出第一个只出现一次的字符的位置
- WCF 入门 WCF基础知识问与答
- 五分钟带你摸透 Vue组件及组件通讯
- 重载类型转换操作符(overload conversion operator)
- 翻译:protocol的高阶用法,在Swift 5中使用协议protocol构建自定义集合Collection
- Rhino.Inside.Revit教程
- HTML 实现扫雷游戏
- 车机没有carlife可以自己下载吗_雷克萨斯NX 原车carlife转换无线carplay
- 求职简历-机器学习工程师
- 【STM32】OOK软解码
- 由于受到新冠疫情的影响,GDP同比增长率从2019年的6.1%下滑到了2.3%
- MarkdownPad2无法预览Markdown文档问题的解决
- 路由汇总带来的三层环路-解决实验
- Redis集群的设计与使用
- 设置py文件在pycharm里的工作环境/路径
- Socket网络编程学习笔记 (10)简易聊天室案例
- 微型计算机在情报检索中的应用属于什么领域,第1章-单选题
热门文章
- about osgeo中国
- chkconfig的用法
- [C++] 用Xcode来写C++程序[6] Name visibility
- 微软职位内部推荐-Senior PM
- 安装apache2.4.10
- malloc和new有什么区别
- [JavaScript] FireBug 调试
- 借助 Subversion 进行版本控制
- android studio设置JDK路径
- shouldOverrideUrlLoading(拦截url加载,除资源请求的url) shouldInterceptRequest(拦截所有url请求)