1、使用uCharts绘制仪表盘


方法:在hbuilderx中安装ucharts插件,uni_modulus会自动插入qiun-data-charts的文件夹,后面直接使用,不用在页面中引入
注意:opts即gauge的相关配置可在ucharts官网在线工具中调好再复制出来
在线工具:https://demo.ucharts.cn/#/

如:
<template>
	<view class="content">
		<view class="warnInfo">
			<view class="warn_title">
				报警信息
			</view>
			<view class="warn_echart">

				<view class="charts_box">
					<!-- 通过opts传值来覆盖config-ucharts.js中的默认配置,自定义配置可以在在线工具中调好再复制 -->
					<qiun-data-charts type="gauge" :chartData="chartData" background="none" :opts="opts" />
				</view>

			</view>

		</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				title: 'Hello',
				chartData: {
					categories: [],
					series: [],
				},
				opts: {}
			}
		},
		onLoad() {

		},
		onReady() {
			//调用绘制方法
			this.getServerData()
		},

		methods: {
			getServerData() {
				setTimeout(() => {
					this.chartData = {
						categories: [{
								"value": 0.2,
								"color": "rgba(220, 142, 22, 0.5)"
							},
							{
								"value": 0.6,
								"color": "rgba(220, 142, 22, 0.8)"
							},
							{
								"value": 1,
								"color": "rgba(220, 142, 22, 1)"
							}
						],
						series: [{
							"name": "报警次数",
							"data": 5
						}]
					}

					this.opts = {
						"type": "gauge",
						"canvasId": "",
						"canvas2d": false,
						"background": "none",
						"animation": true,
						"timing": "easeOut",
						"duration": 1000,
						"color": [
							"#1890FF",
							"#91CB74",
							"#FAC858",
							"#EE6666",
							"#73C0DE",
							"#3CA272",
							"#FC8452",
							"#9A60B4",
							"#ea7ccc"
						],
						"rotate": false,
						"errorReload": true,
						"fontSize": 10,//刻度字体大小
						"fontColor": "#666666",
						"enableScroll": false,
						"touchMoveLimit": 60,
						"enableMarkLine": false,
						"dataLabel": true,
						"dataPointShape": true,
						"dataPointShapeType": "solid",
						"tapLegend": true,
						"title": {
							"name": "4",
							"fontSize": 13,
							"color": "rgba(220, 142, 22, 1)",
							"offsetX": 0,
							"offsetY": 30
						},
						"subtitle": {
							"name": "报警次数",
							"fontSize": 13,
							"color": "rgba(145, 177, 236, 1)",
							"offsetX": 0,
							"offsetY": 35,//调整纵向距离
						},
						"extra": {
							"gauge": {
								"type": "default",
								"width": 10,//环形宽度
								"labelColor": "#91B1EC",
								"labelOffset": 8,//label标注与环形的距离
								"startAngle": 0.75,
								"endAngle": 0.25,
								"startNumber": 0,
								"endNumber": 20,
								"format": "",
								"splitLine": {
									"fixRadius": 0,
									"splitNumber": 4,//分割段数
									"width": 30,
									"color": "transparent",//去掉分割线
									"childNumber": 5,
									"childWidth": 12
								},
								"pointer": {
									"width": 14,
									"color": "rgba(134, 153, 187, 1)"
								},
								"labelFormat": ""
							}
						}
					}
				}, 800)
			}


		},

		mounted() {

		}
	}
</script>

<style lang="scss">
	@mixin flexCenter {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.content {
		width: 100%;
		height: 100%;
		background: #fff;

		.warnInfo {
			width: 100%;
			height: 300upx;
			background: #132040;

			font-size: 30upx;
			color: #fff;

			.warn_title {
				width: 100%;
				height: 60upx;
				line-height: 60upx;
				text-align: left;
				background: #182951;
				padding: 0 40upx;
				box-sizing: border-box;
			}

			.warn_echart {
				width: 100%;
				padding: 0 40upx;
				box-sizing: border-box;
				height: calc(100% - 60upx) !important;
				color: #fff;

				.charts_box {
					width: 100%;
					height: 100%;
				}
			}
		}
	}
</style>

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM