<template>
	<view class="content">
		<view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts" class="echarts"></view>

	</view>
</template>

<script>


	export default {
		name: 'chart',
		props: {

		},
		data() {
			return {
				option: {
					 series: [{
					         type: 'gauge',
							 //半径
							 radius: '80%',	 
					         detail: {
					             color: '#FFC600',
					             fontSize: 30,
					             fontWeight: 'normal',
					             offsetCenter: [0, '70%']  
					         },
					         data: [{
					             value: 30,
					             name: '任务完成率'
					         }],
							  
							   startAngle: 210,
							                  //结束角度。
							                  endAngle: -30,
							                  center: ['50%', '50%'],  //中心位置
					         pointer: {
					 	    	show: true,
								 length: '70%',
					 	    },
					 	    title: {
					 	        offsetCenter: [0, '30%'],
					 	        fontSize: 15,
					 	        color: '#444'
					 	    },
					 	    min:0,
					         max:100,
					         splitNumber: 10,
							 //分隔线样式。
							 splitLine: {
								 show: false,
							 },
					         axisLine: {
					             show: true,
					             lineStyle: {
									  width: 20,
									  // color: [[1, 'red']]
					                 // color: [
					                 //     [1, new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
					                 //             offset: 0.1,
					                 //             color: "#E43F3D"
					                 //         },
					                 //         {
					                 //             offset: 0.15,
					                 //             color: "#E98E2C"
					                 //         },
					                 //         {
					                 //             offset: 0.2,
					                 //             color: "#DDBD4D"
					                 //         },
					                 //         {
					                 //             offset: 0.8,
					                 //             color: "#7CBB55"
					                 //         },
					                 //         {
					                 //             offset: 1,
					                 //             color: "#9CD6CE"
					                 //         }
					                 //     ])]
					                 // ]
					 
					             }
					         },
					      
					 
					     }]}

				
			}
		},
		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('echarts'))
				// 观测更新的数据在 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: 400rpx;

	}
</style>
