<template>
	<view class="charts-box" :style="[{width},{height},]">
		<qiun-data-charts canvas2d type="arcbar" errorType="1" :errorMessage="errorMessage" :errorReload="false"
			:opts="opts" :chartData="chartData" />
	</view>
</template>

<script>
	export default {
		props: {
			width: {
				type: String,
				default: '170rpx'
			},
			height: {
				type: String,
				default: '170rpx'
			},
			canvasId: {
				type: String,
				default: ''
			},
			bgColor: {
				type: String,
				default: () => {
					return '#0FB160'
				}
			},
		},
		data() {
			return {
				errorMessage: '',
				isCanvas2d: process.uniEnv.isCanvas2d,
				chartData: {},
				//这里的 opts 是图表类型 type="arcbar" 的全部配置参数，您可以将此配置复制到 config-ucharts.js 文件中下标为 ['arcbar'] 的节点中来覆盖全局默认参数。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					timing: "easeOut",
					duration: 1000,
					rotate: false,
					rotateLock: false,
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: undefined,
					fontSize: 13,
					fontColor: "#666666",
					dataLabel: true,
					dataPointShape: true,
					dataPointShapeType: "solid",
					touchMoveLimit: 60,
					enableScroll: false,
					enableMarkLine: false,
					title: {
						name: "",
						fontSize: 25,
						color: "#00FF00",
						offsetX: 0,
						offsetY: 0
					},
					subtitle: {
						name: "0%",
						fontSize: 15,
						color: "#666666",
						offsetX: 0,
						offsetY: 0
					},
					extra: {
						arcbar: {
							type: "circle",
							width: 10,
							backgroundColor: "#E9E9E9",
							startAngle: 0.5,
							endAngle: 0.25,
							gap: 2,
							direction: "cw",
							lineCap: "round",
							centerX: 0,
							centerY: 0,
							linearType: "none"
						}
					}
				}
			};
		},
		onReady() {
			// this.getServerData();
      console.log(process.uniEnv.isCanvas2d)
		},
		methods: {
			getServerData() {
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let res = {
						series: [{
							name: "0%",
							// color: this.bgColor,
							data: 0
						}]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
				}, 500);
			},
			notServerData() {
				this.chartData = {};
				this.errorMessage = '暂无数据'
			},
			setServerData(data) {
				this.opts.subtitle.name = (data * 100).toFixed(0) + "%"
				setTimeout(() => {
					let res = {
						series: [{
							color: this.bgColor,
							data: data
						}]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
					// this.notServerData()
				}, 100)
			},
		}
	};
</script>

<style scoped>
</style>