| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 | 
							- <template>
 
- 	<view class="content">
 
- 		<view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts2" class="echarts"></view>
 
- 	</view>
 
- </template>
 
- <script>
 
- 	// let echartData = [{
 
- 	// 		name: "报警",
 
- 	// 		value: 1000
 
- 	// 	},
 
- 	// 	{
 
- 	// 		name: "事件",
 
- 	// 		value: 2920
 
- 	// 	},
 
- 	// 	{
 
- 	// 		name: "隐患",
 
- 	// 		value: 2200
 
- 	// 	},
 
- 	// ];
 
- 	 let title = '总数';
 
- 	// let total = echartData.reduce((a, b) => {
 
- 	// 	return a + b.value * 1
 
- 	// }, 0);
 
- 	export default {
 
- 		props:{
 
- 			bindData:{
 
- 				type:Object,
 
- 				default: ''
 
- 			}
 
- 		},
 
- 		data() {
 
- 			return {
 
- 				option: {
 
- 					color: ['#F67F32', '#3BD2BD', '#1DABFE'],
 
- 					title: {
 
- 						left: 'center'
 
- 					},
 
- 					tooltip: {
 
- 						trigger: 'item',
 
- 						// formatter: "{a} <br/>{b}: {c} ({d}%)"
 
- 						formatter: "{b}: {c} "
 
- 					},
 
- 					title: [{ //aa标题
 
- 						text: '{val|' +(parseInt(this.bindData.alarmCount)+parseInt(this.bindData.eventCount)+ parseInt(this.bindData.hiddenDangerCount))+ '}\n{name|' + title + '}',
 
- 						top: '45%',
 
- 						left: 'center',
 
- 						textStyle: {
 
- 							rich: {
 
- 								name: {
 
- 									fontSize: 14,
 
- 									fontWeight: 'normal',
 
- 									color: '#666666',
 
- 									padding: [5, 0]
 
- 								},
 
- 								val: {
 
- 									fontSize: 24,
 
- 									color: '#333333',
 
- 								}
 
- 							}
 
- 						}
 
- 					}],
 
- 					legend: { //aa图例
 
- 						orient: 'horizontal',
 
- 						icon: 'circle',
 
- 						itemWidth: 12,
 
- 						itemHeight: 12,
 
- 						itemGap: 60,
 
- 						// top: -10,
 
- 						textStyle: {
 
- 							fontSize: 14,
 
- 							rich: {
 
- 								name: {
 
- 									fontSize: 18
 
- 								},
 
- 								value: {
 
- 									fontSize: 14,
 
- 									padding: [0, 20, 0, 5]
 
- 								},
 
- 							}
 
- 						},
 
- 					},
 
- 					series: [{
 
- 						name: '访问来源',
 
- 						type: 'pie',
 
- 						radius: ['40%', '60%'],
 
- 						center: ['50%', '55%'],
 
- 						itemStyle: {
 
- 							normal: {
 
- 								shadowBlur: 20,
 
- 								shadowColor: '#F9F5F7',
 
- 								shadowOffsetX: 0,
 
- 								shadowOffsetY: 0,
 
- 							},
 
- 						},
 
- 						data: [{
 
- 								name: "报警",
 
- 								value: this.bindData.alarmCount
 
- 							},
 
- 							{
 
- 								name: "事件",
 
- 								value: this.bindData.eventCount
 
- 							},
 
- 							{
 
- 								name: "隐患",
 
- 								value: this.bindData.hiddenDangerCount
 
- 							},
 
- 						],
 
- 						emphasis: {
 
- 							itemStyle: {
 
- 								shadowBlur: 10,
 
- 								shadowOffsetX: 0,
 
- 								shadowColor: 'rgba(0, 0, 0, 0.5)'
 
- 							}
 
- 						},
 
- 						labelLine: {
 
- 							normal: {
 
- 								length: 10, //aa折线长度
 
- 								length2: 20, //aa折线长度
 
- 							}
 
- 						},
 
- 						label: {
 
- 							normal: {
 
- 								formatter: '{b}:{d}%',
 
- 								// formatter: params => {
 
- 								// 	var percent = 0;
 
- 								// 	var total = 0;
 
- 								// 	for (var i = 0; i < echartData.length; i++) {
 
- 								// 		total += echartData[i].value;
 
- 								// 	}
 
- 								// 	console.log(111);
 
- 								// 	console.log(total);
 
- 								// 	percent = ((params.value / total) * 100).toFixed(0);
 
- 								// 	return params.name + ': ' + percent + '%';
 
- 								// },
 
- 							}
 
- 						},
 
- 					}]
 
- 				}
 
- 			}
 
- 		},
 
- 		onLoad() {
 
- 		},
 
- 		methods: {
 
- 			changeOption() {
 
- 				const data = this.option.series[0].data
 
- 				// 随机更新示例数据
 
- 				data.forEach((item, index) => {
 
- 					data.splice(index, 1, Math.random() * 40)
 
- 				})
 
- 			},
 
- 			onViewClick(options) {
 
- 				console.log(options)
 
- 			}
 
- 		}
 
- 	}
 
- </script>
 
- <script module="echarts" lang="renderjs">
 
- 	let myChart
 
- 	export default {
 
- 		mounted() {
 
- 			if (typeof window.echarts === 'function') {
 
- 				this.initEcharts()
 
- 			} else {
 
- 				// 动态引入较大类库避免影响页面展示
 
- 				const script = document.createElement('script')
 
- 				// view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
 
- 				script.src = '/static/echarts.min.js'
 
- 				script.onload = this.initEcharts.bind(this)
 
- 				document.head.appendChild(script)
 
- 			}
 
- 		},
 
- 		methods: {
 
- 			initEcharts() {
 
- 				myChart = echarts.init(document.getElementById('echarts2'))
 
- 				// 观测更新的数据在 view 层可以直接访问到
 
- 				myChart.setOption(this.option)
 
- 			},
 
- 			updateEcharts(newValue, oldValue, ownerInstance, instance) {
 
- 				// 监听 service 层数据变更
 
- 				myChart.setOption(newValue)
 
- 			},
 
- 			onClick(event, ownerInstance) {
 
- 				// 调用 service 层的方法
 
- 				ownerInstance.callMethod('onViewClick', {
 
- 					test: 'test'
 
- 				})
 
- 			}
 
- 		}
 
- 	}
 
- </script>
 
- <style>
 
- 	.content {
 
- 		display: flex;
 
- 		flex-direction: column;
 
- 		align-items: center;
 
- 		justify-content: center;
 
- 	}
 
- 	.echarts {
 
- 		width: 100%;
 
- 		height: 500rpx;
 
- 		margin-top: 70rpx;
 
- 	}
 
- </style>
 
 
  |