/* * @Descripttion: * @version: * @Author: sueRimn * @Date: 2020-09-02 16:22:35 * @LastEditors: sueRimn * @LastEditTime: 2020-09-05 16:27:05 */ import { Component, OnInit } from '@angular/core'; import { Router,ActivatedRoute } from '@angular/router'; import {EchartsDataService} from '../../echarts-data.service'; import { MatSnackBarConfig, MatSnackBar } from '@angular/material/snack-bar'; import { DateAdapter } from '@angular/material/core'; declare var echarts: any; @Component({ selector: 'app-delete-there', templateUrl: './delete-there.component.html', styleUrls: ['./delete-there.component.scss'] }) export class DeleteThereComponent implements OnInit { constructor(private router: Router,private activatedRoute: ActivatedRoute,public echartsData:EchartsDataService,public snackBar: MatSnackBar,private adapter: DateAdapter) { } zhutu//echarts实例 ngOnDestroy():void{ this.zhutu.clear() this.zhutu.dispose() } ngOnInit(): void { let headtext:string; let datayuex:string; let headName:string; this.activatedRoute.params.subscribe(param=>{ headtext=param.headtext datayuex=param.datayuex headName=headtext+''+datayuex; //console.log(datayuex) }); window.setTimeout(()=>{ this.zhuzhuangtu(this.echartsData.statefulInspectionName) },0) } zhiNameData = ["浦东支队","黄埔支队","徐汇支队","长宁支队","静安支队","普陀支队","虹口支队","杨浦支队","闵行支队","宝山支队","嘉定支队","松江支队","金山支队","崇明支队"] zhiNumData = [200,190,180,170,160,150,140,130,120,110,100,90,80,70] //返回 goBack () { history.go(-1) this.echartsData.statefulInspectionToggle = true } axisLabel = { interval: 0, formatter:function(value) { var ret = "";//拼接加\n返回的类目项 var maxLength = 2;//每项显示文字个数 var valLength = value.length;//X轴类目项的文字个数 var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数 if (rowN > 1)//如果类目项的文字大于3, { for (var i = 0; i < rowN; i++) { var temp = "";//每次截取的字符串 var start = i * maxLength;//开始截取的位置 var end = start + maxLength;//结束截取的位置 //这里也可以加一个是否是最后一行的判断,但是不加也没有影响,那就不加吧 temp = value.substring(start, end) + "\n"; ret += temp; //凭借最终的字符串 } return ret; } else { return value; } } }//echarts两个字换行 /* 柱状图 */ zhuzhuangtu(headName:string){ var ec = echarts as any; this.zhutu = ec.init(document.getElementById('zhidui')); var option = { title: { text: `${headName}`, left: "center", top: "15", textStyle: { fontSize: 23 } }, /* grid: { left: '5%', bottom:'35%' }, */ xAxis: { type: 'category', data: this.zhiNameData, axisLabel: this.axisLabel }, yAxis: { type: 'value' }, tooltip: { trigger: 'item', formatter: (params)=>{ return this.tableTooltip2(params.name) }, backgroundColor:'rgba(255,255,255,1)',//通过设置rgba调节背景颜色与透明度 borderWidth:'1', borderRadius :'0' }, series: [{ data: this.zhiNumData, type: 'bar', showBackground: true, backgroundStyle: { color: 'rgba(220, 220, 220, 0.8)' }, barWidth :'58', //label: this.topTextlabel }] }; this.zhutu.on('click', (params) => { console.log(params) this.echartsData.statefulInspectionName =params.name; this.router.navigateByUrl(`/statisticanalysis/delete_one/delete_four`); }); this.zhutu.setOption(option); } /* 鼠标悬停提示 */ tableTooltip2(biaotou:string){ var shuju='[{"name":"浦东中队","number":"156","zhanbi":"3%"},{"name":"黄埔中队","number":"144","zhanbi":"2.8%"},' shuju+='{"name":"徐汇中队","number":"133","zhanbi":"2.1%"},{"name":"长宁中队","number":"122","zhanbi":"1.6%"},' shuju+='{"name":"静安中队","number":"120","zhanbi":"1.3%"},{"name":"普陀中队","number":"100","zhanbi":"1.1%"},' shuju+='{"name":"虹口中队","number":"95","zhanbi":"1%"},{"name":"杨浦中队","number":"90","zhanbi":"0.9%"},' shuju+='{"name":"闵行中队","number":"88","zhanbi":"0.8%"},{"name":"宝山中队","number":"83","zhanbi":"0.7%"},' shuju+='{"name":"徐汇中队","number":"133","zhanbi":"2.1%"},{"name":"长宁中队","number":"122","zhanbi":"1.6%"},' shuju+='{"name":"嘉定中队","number":"78","zhanbi":"0.6%"},{"name":"松江中队","number":"75","zhanbi":"0.5%"},' shuju+='{"name":"金山中队","number":"65","zhanbi":"0.4%"},{"name":"崇明中队","number":"55","zhanbi":"0.3%"}]' var jsonObj = JSON.parse(shuju); var res = '
'+biaotou+'
' res+='
'; res+=''; res+=''; res+='' res+='' res+='' res+=''; for(var i=0;i' res+='' res+='' } res+='' res+='' res+='
名称数量总占比
'+jsonObj[i].number+''+jsonObj[i].zhanbi+'
总计135619%
' return res } }