Zt il y a 1 an
Parent
commit
183b489e33

+ 117 - 0
reado-app/components/ecahrts/demo1.vue

@@ -0,0 +1,117 @@
+<template>
+	<view class="dataTable">
+		<canvas id="myEcharts" style="width:100%;height:540rpx"></canvas>
+	</view>
+</template>
+
+<script>
+	// 将npm方式下载的echarts插件引入进来
+	import * as echarts from 'echarts';
+	export default {
+		data() {
+			return {
+				// 这里初始化一个null,待会儿用来充当echarts实例
+				myChart: null,
+			}
+		},
+		mounted(options) {
+			let that = this;
+			that.drawLines();
+		},
+		beforeDestroy() {
+			// 页面关闭时销毁echarts实例
+			this.myChart.clear();
+			this.myChart.dispose();
+		},
+		methods: {
+			async drawLines() {
+				// 这里是初始化的方式,通过id查询找到你的canvas标签
+				this.myChart = echarts.init(document.getElementById('myEcharts'));
+
+				let base = +new Date(1968, 9, 3);
+				let oneDay = 24 * 3600 * 1000;
+				let date = [];
+				let data = [Math.random() * 300];
+				for (let i = 1; i < 20000; i++) {
+					var now = new Date((base += oneDay));
+					date.push([now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'));
+					data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1]));
+				}
+				// 这里开始就是echarts的配置项了
+				let option = {
+					tooltip: {
+						trigger: 'axis',
+						position: function(pt) {
+							return [pt[0], '10%'];
+						}
+					},
+					title: {
+						left: 'center',
+						text: 'Large Area Chart'
+					},
+					toolbox: {
+						feature: {
+							dataZoom: {
+								yAxisIndex: 'none'
+							},
+							restore: {},
+							saveAsImage: {}
+						}
+					},
+					xAxis: {
+						type: 'category',
+						boundaryGap: false,
+						data: date
+					},
+					yAxis: {
+						type: 'value',
+						boundaryGap: [0, '100%']
+					},
+					dataZoom: [{
+							type: 'inside',
+							start: 0,
+							end: 10
+						},
+						{
+							start: 0,
+							end: 10
+						}
+					],
+					series: [{
+						name: 'Fake Data',
+						type: 'line',
+						symbol: 'none',
+						sampling: 'lttb',
+						itemStyle: {
+							color: 'rgb(255, 70, 131)'
+						},
+						areaStyle: {
+							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
+									offset: 0,
+									color: 'rgb(255, 158, 68)'
+								},
+								{
+									offset: 1,
+									color: 'rgb(255, 70, 131)'
+								}
+							])
+						},
+						data: data
+					}]
+				}
+
+				// 这里不要忘记把option设置给echarts实例
+				this.myChart.setOption(option);
+
+				// 这里是用于窗口变化时的自适应,利用的是echarts自带的resize方法
+				// 如果你打印出来这个echarts实例,可以在函数里面找到这个方法
+				window.addEventListener('resize', () => {
+					this.myChart.resize()
+				});
+			},
+		},
+	}
+</script>
+
+<style>
+</style>

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
reado-app/components/ecahrts/echarts.min.js


+ 3 - 9
reado-app/pages/homePage/index.vue

@@ -36,9 +36,7 @@
 						{{item.chartName}}
 					</view>
 					<!-- <lineEcharts :echartsData="item" /> -->
-					<view class="wv-content">
-						<web-view :src="item.src" style="top:4vh;width:100%;height:320px;"></web-view>
-					</view>
+					<web-view :src="item.src" style="top:7vh;width:100%;height:320px;"></web-view>
 				</view>
 			</view>
 		</template>
@@ -166,7 +164,8 @@
 					const data = res.data
 					if (data.code === 200) {
 						if (data.data.chartType === 'line') {
-							data.data.src = `/static/webview/line-wv.html?id=${data.data.id}&startTime=${this.startTime}` 
+							data.data.src =
+								`/static/webview/line-wv.html?id=${data.data.id}&startTime=${this.startTime}`
 						}
 						this.echartsData.push(data.data)
 					}
@@ -249,9 +248,4 @@
 		width: 80rpx;
 		text-align: center;
 	}
-
-	.wv-content {
-		width: 100%;
-		height: 540rpx;
-	}
 </style>

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
reado-app/static/webview/echarts.min.js


+ 168 - 37
reado-app/static/webview/line-wv.html

@@ -9,7 +9,7 @@
 	</head>
 
 	<body>
-		<div id="main" style="width:380px;height:300px"></div>
+		<div id="main" style="width:340px;height:300px;margin:auto"></div>
 
 		<script src="./echarts.min.js"></script>
 		<script type="text/javascript" src="../luckysheet/dist/plugins/js/uni-webview-js0.0.3_index.js"></script>
@@ -59,17 +59,84 @@
 		</script>
 
 		<script>
+			var option = {
+				xAxis: {
+					type: 'category',
+					data: [],
+					axisLabel: {
+						// formatter: function(value) {
+						// 	const result = value.replaceAll('-', '').substring(0,
+						// 		9);
+						// 	return result
+						// }
+						formatter: '{value}'
+					}
+				},
+				yAxis: {
+					type: 'value'
+				},
+				legend: {
+					type: 'scroll',
+					top: 0
+				},
+				tooltip: {
+					trigger: 'axis',
+					axisPointer: {
+						type: 'cross',
+						lineStyle: {
+							type: 'dashed'
+						},
+						label:{
+							show:false
+						}
+					},
+					backgroundColor: 'rgba(50,50,50,0.5)',
+					formatter: function(params) {
+						let result = ''
+						for (let i in params) {
+							if (i == 0) {
+								result += params[i].axisValueLabel
+									.substring(9, 17)
+							}
+							let value = '--'
+							if (params[i].data !== null) {
+								value = params[i].data
+							}
+							result += '\n' + params[i].seriesName + ':' +
+								value
+						}
+						return result
+					}
+				},
+				dataZoom: [{
+						type: 'inside',
+						start: 0,
+						end: 10
+					},
+					{
+						type: 'slider',
+						show: true,
+						start: 0,
+						end: 10
+					}
+				],
+				series: []
+			};
+		</script>
+
+		<script>
 			document.addEventListener('UniAppJSBridgeReady', function() {
 				uni.getEnv(function(res) {
 					const id = GetQueryString('id')
 					const startTime = GetQueryString('startTime')
 					const endTime = nowDate()
 					const token = window.localStorage.getItem('C_TOKEN')
+					var echartsData
 					let chartParams = {
 						id: id
 					}
 					$.ajax({
-						url: "" + id,
+						url: "",
 						type: 'GET',
 						beforeSend: function(xhr) {
 							this.url =
@@ -80,44 +147,108 @@
 						},
 						success: function(res) {
 							if (res.code === 200) {
-								const chartData = res.data.chartItemList
-								const timeData = chartData[0].valueTimeList
-
-								const series = chartData.map(item => {
-									return {
-										name: item.describe ? item.describe : item.itemName,
-										data: item.valueList,
-										type: 'line'
-									}
-								})
-
-								var chart = echarts.init(document.getElementById('main'));
-								let option = {
-									xAxis: {
-										type: 'category',
-										data: timeData
-									},
-									yAxis: {
-										type: 'value'
-									},
-									dataZoom: [{
-											type: 'inside',
-											start: 0,
-											end: 10
-										},
-										{
-											type: 'slider',
-											show: false,
-											start: 0,
-											end: 10
-										}
-									],
-									series: series
-								};
-								chart.setOption(option)
+								echartsData = res.data.chartItemList
+
+								getServerData(echartsData)
+
+								getEmit(res)
 							}
 						}
 					})
+
+					function initEcharts() {
+						var chart = echarts.init(document.getElementById('main'));
+						chart.setOption(option)
+					}
+
+					function getServerData(echartsData) {
+						const chartData = echartsData
+						const timeData = chartData[0].valueTimeList
+
+						const series = chartData.map(item => {
+							return {
+								name: item.describe ? item.describe : item.itemName,
+								data: item.valueList,
+								type: 'line'
+							}
+						})
+						option.xAxis.data = timeData
+						option.series =series
+						initEcharts()
+					}
+
+					function getEmit(res) {
+						const {
+							bucketType,
+							bucketValue
+						} = res.data
+						var time = null
+						switch (bucketType) {
+							case 0:
+								time = 86400000 * bucketValue
+
+								break;
+							case 1:
+								time = 3600000 * bucketValue
+
+								break;
+							case 2:
+								time = 60000 * bucketValue
+
+								break;
+							case 3:
+								time = 1000 * bucketValue
+
+								break;
+						}
+						var lineTime = setInterval(() => {
+							const currentTime = nowDate();
+							var lastTime = localStorage.getItem('sTime');
+							localStorage.setItem('sTime', currentTime)
+							$.ajax({
+								url: "",
+								type: 'GET',
+								beforeSend: function(xhr) {
+									this.url =
+										`http://192.168.0.40:8081/chart/getChartById?id=${id}&startTime=${lastTime}&endTime=${currentTime}`
+									xhr.setRequestHeader("Authorization", "Bearer " +
+										token);
+									xhr.setRequestHeader("token", token);
+								},
+								success: function(res) {
+									if (res.code === 200) {
+										let chartItemList = res.data.chartItemList;
+										chartItemList.forEach((item, index) => {
+											if (item.itemId === echartsData[
+													index].itemId) {
+												if (item.valueList.length !== 0) {
+													//执行将新数据添加进去,旧数据去除一个
+													echartsData[index].valueList =
+														echartsData[index].valueList
+														.concat(item.valueList)
+													echartsData[
+															index]
+														.valueList.splice(0, item
+															.valueList.length)
+													echartsData[index]
+														.valueTimeList = echartsData[
+															index]
+														.valueTimeList.concat(item
+															.valueTimeList)
+													echartsData[
+															index]
+														.valueTimeList.splice(0,
+															item
+															.valueTimeList.length)
+												}
+											}
+										})
+										getServerData(echartsData)
+									}
+								}
+							})
+						}, time)
+					}
 				})
 			})
 		</script>

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff