uni-app:实现页面效果4(echarts数据可视化)

news2024/10/2 16:24:41

效果

代码

<template>
	<view>
		<view>
			<view class="title">概况</view>
			<view class="line_position">
				<view class="line1">
					<view class="item">
						<view class="one">今日销售额(万元)</view>
						<view class="two">
							<view class="left">{{line1_info.daysale_allamount}}</view>
							<view class="right">{{line1_info.daychangeRate}}</view>
						</view>
						<view class="three">
							<image :src="getImagePath(line1_info.daychangeRate)" alt=""></image>
						</view>
					</view>
					<view class="item">
						<view class="one">本周销售额(万元)</view>
						<view class="two">
							<view class="left">{{line1_info.weeksale_allamount}}</view>
							<view class="right">{{line1_info.weekchangeRate}}</view>
						</view>
						<view class="three">
							<image :src="getImagePath(line1_info.weekchangeRate)" alt=""></image>
						</view>
					</view>
					<view class="item">
						<view class="one">本月销售额(万元)</view>
						<view class="two">
							<view class="left">{{line1_info.monthsale_allamount}}</view>
							<view class="right">{{line1_info.monthchangeRate}}</view>
						</view>
						<view class="three">
							<image :src="getImagePath(line1_info.monthchangeRate)" alt=""></image>
						</view>
					</view>
					<view class="item">
						<view class="one">今年销售额(万元)</view>
						<view class="two">
							<view class="left">{{line1_info.yearsale_allamount}}</view>
							<view class="right">{{line1_info.yearchangeRate}}</view>
						</view>
						<view class="three">
							<image :src="getImagePath(line1_info.yearchangeRate)" alt=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view>
			<view class="title">销售额统计</view>
			<view class="tab_position">
				<view class="tab-bar">
					<text class="tab" :class="{ 'active': activeTab === '0' }" @click="changeTab('0')">周统计</text>
					<text class="tab" :class="{ 'active': activeTab === '1' }" @click="changeTab('1')">月统计</text>
					<text class="tab" :class="{ 'active': activeTab === '2' }" @click="changeTab('2')">年统计</text>
				</view>
			</view>
			<view v-show="activeTab === '0'">
				<view class="out">
					<view id="myChart"></view>
				</view>
			</view>
			<view v-show="activeTab === '1'">
				<view class="out">
					<view id="myChart1"></view>
				</view>
			</view>
			<view v-show="activeTab === '2'">
				<view class="out">
					<view id="myChart2"></view>
				</view>
			</view>
		</view>



	</view>
</template>
<script>
	// import echarts from '@/static/js/echarts.js' // 引入文件
	import * as echarts from 'echarts';
	export default {
		data() {
			return {
				line1_info: '',
				down: getApp().globalData.icon + 'report/down.png',
				up: getApp().globalData.icon + 'report/up.png',
				line: getApp().globalData.icon + 'report/line.png',
				activeTab: '0', //默认分页面
				weekinfo: [], // 定义一个空数组用于存储周统计数据
				monthinfo: [], // 定义一个空数组用于存储月统计数据
			}
		},
		methods: {
			//切换分页面
			changeTab(index) {
				this.activeTab = index;
			},
			//图片展示
			getImagePath(rate) {
				if (rate === "无法计算") {
					return this.line;
				} else if (rate && rate.startsWith("-")) {
					return this.down;
				} else {
					return this.up;
				}
			},
			getdata() {
				uni.request({
					url: getApp().globalData.position + 'Other/select_sale_ekanbaninfo',
					data: {},
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					method: 'POST',
					dataType: 'json',
					success: res => {
						//行1:年月日总额统计
						this.line1_info = res.data;
						//行2:周统计
						var weekinfo = res.data.week_info;
						this.weekinfo = weekinfo;
						//行2:月统计
						var monthinfo = res.data.month_info;
						this.monthinfo = monthinfo;
						//行2:年统计
						var yearinfo = res.data.year_info;
						this.yearinfo = yearinfo;
						console.log(this.yearinfo)
						//显示图表
						this.echart();
					},
					fail(res) {
						console.log("查询失败")
					}
				});
			},
			//绘制图标
			echart() {
				// 周统计金额
				const myChart = echarts.init(document.getElementById('myChart'))
				// 提取日期和对应的值
				var dates = this.weekinfo.date;
				var values = this.weekinfo.total_amount;
				var weeks = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"];
				// 进行图表的配置和数据处理
				myChart.setOption({
					//配置网格组件,用于定义图表的位置和大小
					grid: {
						top: '15%', // 增加top的值来创建间距
						left: '2%',
						right: '2%',
						bottom: '2%', // 增加bottom的值来创建间距
						containLabel: true, //自动计算并包含坐标轴标签、刻度和标题等内容在内。
					},
					color: ['#e57b7b'],
					tooltip: {
						trigger: 'item',
						axisPointer: {
							type: 'line'
						},
						formatter: function(params) {
							var value = values[params.dataIndex];
							var date = dates[params.dataIndex];
							var week = weeks[params.dataIndex];
							var marker = params.marker; // 添加marker(小圆点)
							return marker + ' ' + date + '<br/>' + week + ' : ' + value + '万元';
						}
					},
					xAxis: {
						// name: '日期',
						data: weeks,
						axisLine: {
							show: false // 隐藏纵坐标轴的横线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					yAxis: {
						name: '金额(万元)',
						splitLine: {
							show: false // 隐藏纵坐标轴的背景横线
						},
						axisLine: {
							show: false // 隐藏纵坐标轴的竖线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						axisLabel: {
							fontSize: 12 // 设置横轴标签字体大小为12
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					series: [{
						barWidth: '8',
						name: '销量',
						type: 'bar',
						data: values,
						itemStyle: {
							show: true,
							position: 'top',
							textStyle: {
								// color: '#515dc3',
								fontSize: 12
							}
						}
					}]
				});
				//月统计
				// 周统计金额
				const myChart1 = echarts.init(document.getElementById('myChart1'))
				// 提取日期和对应的值
				var dates1 = this.monthinfo.date;
				var values1 = this.monthinfo.total_amount;
				var months1 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
				var months1_chinese = ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"];
				// 进行图表的配置和数据处理
				myChart1.setOption({
					//配置网格组件,用于定义图表的位置和大小
					grid: {
						top: '15%', // 增加top的值来创建间距
						left: '2%',
						right: '2%',
						bottom: '2%', // 增加bottom的值来创建间距
						containLabel: true, //自动计算并包含坐标轴标签、刻度和标题等内容在内。
					},
					color: ['#5588d4'],
					tooltip: {
						trigger: 'item',
						axisPointer: {
							type: 'line'
						},
						formatter: function(params) {
							var value = values1[params.dataIndex];
							var date = dates1[params.dataIndex];
							var month = months1_chinese[params.dataIndex];
							var marker = params.marker; // 添加marker(小圆点)
							return marker + ' ' + date + '<br/>' + month + ' : ' + value + '万元';
						}
					},
					xAxis: {
						// name: '日期',
						data: months1,
						axisLine: {
							show: false // 隐藏纵坐标轴的横线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					yAxis: {
						name: '金额(万元)',
						splitLine: {
							show: false // 隐藏纵坐标轴的背景横线
						},
						axisLine: {
							show: false // 隐藏纵坐标轴的竖线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						axisLabel: {
							fontSize: 12 // 设置横轴标签字体大小为12
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					series: [{
						barWidth: '6',
						name: '销量',
						type: 'bar',
						data: values1,
						itemStyle: {
							show: true,
							position: 'top',
							textStyle: {
								// color: '#515dc3',
								fontSize: 12
							}
						}
					}]
				});
				//近五年年统计
				// 年统计金额
				const myChart2 = echarts.init(document.getElementById('myChart2'))
				// 提取日期和对应的值
				var dates2 = this.yearinfo.date;
				var values2 = this.yearinfo.total_amount;
				// 进行图表的配置和数据处理
				myChart2.setOption({
					//配置网格组件,用于定义图表的位置和大小
					grid: {
						top: '15%', // 增加top的值来创建间距
						left: '2%',
						right: '2%',
						bottom: '2%', // 增加bottom的值来创建间距
						containLabel: true, //自动计算并包含坐标轴标签、刻度和标题等内容在内。
					},
					color: ['#71aa77'],
					tooltip: {
						trigger: 'item',
						axisPointer: {
							type: 'line'
						},
						formatter: function(params) {
							var value = values2[params.dataIndex];
							var date = dates2[params.dataIndex];
							var marker = params.marker; // 添加marker(小圆点)
							return marker + ' ' + date + '年' + '<br/>' + value + '万元';
						}
					},
					xAxis: {
						// name: '日期',
						data: dates2,
						axisLine: {
							show: false // 隐藏纵坐标轴的横线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					yAxis: {
						name: '金额(万元)',
						splitLine: {
							show: false // 隐藏纵坐标轴的背景横线
						},
						axisLine: {
							show: false // 隐藏纵坐标轴的竖线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						axisLabel: {
							fontSize: 12 // 设置横轴标签字体大小为12
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					series: [{
						barWidth: '8',
						name: '销量',
						type: 'bar',
						data: values2,
						itemStyle: {
							normal: {
								label: {
									show: true,
									position: 'top',
									textStyle: {
										// color: '#515dc3',
										fontSize: 12
									}
								}
							}
						}
					}]
				})
			},
		},
		onLoad() {
			this.getdata();
		},
	}
</script>
<style lang="scss">
	//第一行内容
	.title {
		// border:1px solid black;
		padding-left: 2%;
		font-size: 105%;
	}

	.line_position {
		overflow-x: scroll;
		scroll-behavior: smooth; // 设置滚动平滑过渡

		//隐藏滚动条
		&::-webkit-scrollbar {
			width: 0; // 隐藏默认的滚动条 
			height: 0;
		}

		&::-webkit-scrollbar-thumb {
			background-color: transparent; // 隐藏滚动条拖拽的小方块
		}

		.line1 {
			width: 400%;
			display: flex;

			// border:1px solid red;
			.item:nth-child(1) {
				background-color: #515dc3;
			}

			.item:nth-child(2) {
				background-color: #ff9a3e;
			}

			.item:nth-child(3) {
				background-color: #38bf80;
			}

			.item:nth-child(4) {
				background-color: #fc5959;
			}

			.item {
				width: 40%;
				margin: 1% 2%;
				border-radius: 5px;
				padding: 1% 1% 0 1%;
				// border:1px solid red;
				color: white;

				.two {
					display: flex;
					margin: 5% 0;
					align-items: center;

					// border:1px solid red;
					.left {
						width: 70%;
						font-size: 24px;
						// border:1px solid red;
					}

					.right {
						text-align: right;
						width: 30%;
						// border:1px solid red;
					}
				}

				.three {
					text-align: center;

					// border:1px solid red;
					image {
						width: 60px;
						height: 50px;
					}
				}
			}
		}
	}

	//第二行内容
	.tab_position {
		width: 100%;
		display: flex;
		justify-content: center;
	}

	.tab-bar {
		display: flex;
		justify-content: space-between;
		width: 90%;
		// border: 1px solid black;
		background-color: #f2f2f2;
		border-radius: 15px;
		margin: 3% 1%;
	}

	.tab {
		padding: 5px;
		font-size: 16px;
		cursor: pointer;
		// border: 1px solid black;
		width: 33%;
		text-align: center;
		// border-bottom: 1px solid #ccc;
	}

	.active {
		color: white;
		background-color: #515dc3;
		border-radius: 15px;
		/* background-color:#74bfe7; */
		// border-bottom: 1px solid #74bfe7;
	}

	//图标
	.out {
		width: 800rpx;
		// border:1px solid red;
		display: flex;
		justify-content: center;
	}

	#myChart {
		width: 700rpx;
		height: 600rpx;
	}

	#myChart1 {
		width: 700rpx;
		height: 600rpx;
	}

	#myChart2 {
		width: 700rpx;
		height: 600rpx;
	}
</style>

这样写会发现在手机端无法正常运

现改用renderjs进行重写

后端代码

 //查询销售看板需要使用的数据
    public function select_sale_ekanbaninfo(){
        $yesterday = strtotime('-1 day', strtotime(date('Y-m-d')));//获得昨天的时间戳
        $today = strtotime(date('Y-m-d')); // 获取当前日期的时间戳
        $data['today'] = $today;
        // 获取本周开始和结束时间戳
        $thisWeekStart = strtotime('this week', $today);
        $thisWeekEnd = strtotime('next week', $today) - 1;
        // 获取上一周开始和结束时间戳
        $lastWeekStart = strtotime('-1 week', $thisWeekStart);
        $lastWeekEnd = strtotime('-1 week', $thisWeekEnd);
        // 获取本月的开始和结束时间戳
        $thisMonthStart = strtotime('first day of this month', $today);
        $thisMonthEnd = strtotime('last day of this month', $today);
        // 获取上一个月的开始和结束时间戳
        $lastMonthStart = strtotime('first day of last month', $today);
        $lastMonthEnd = strtotime('last day of last month', $today);
        // 获取今年的开始和结束时间戳
        $thisYearStart = strtotime('first day of January', $today);
        $thisYearEnd = strtotime('last day of December', $today);
        // 获取去年的开始和结束时间戳
        $lastYearStart = strtotime('-1 year', $thisYearStart);
        $lastYearEnd = strtotime('-1 year', $thisYearEnd);
        
        // $oneMonthAgo = strtotime('-1 month'); // 获取一个月前的时间戳
        // $oneYearAgo = strtotime('-1 year'); // 获取一年前的时间戳
        // 获取昨天的总金额
        $data['yesterday_allamount'] = Db::table('so_headers_all')
            ->where('creation_date', '>=', $yesterday)
            ->where('creation_date', '<', $today)
            ->sum('order_all_amount');
        //当天的总金额
        $data['daysale_allamount'] = Db::table('so_headers_all')
            ->where('creation_date', '>=', $today) // 筛选 creation_date 大于等于今天的记录
            ->sum('order_all_amount'); // 求和 order_all_amount 列的值
        // 计算日涨幅比率
        if ($data['yesterday_allamount'] == 0) {
             $data['weekchangeRate'] = '无法计算'; 
        }
        else{
            $data['daychangeRate'] = ($data['daysale_allamount'] - $data['yesterday_allamount']) / $data['yesterday_allamount'] * 100;
            if ($data['daychangeRate'] >= 0) {
                $data['daychangeRate'] = '+' . number_format($data['daychangeRate'], 2) . '%';
            } else {
                $data['daychangeRate'] = number_format($data['daychangeRate'], 2) . '%';
            }
        }
        $data['daysale_allamount'] = number_format($data['daysale_allamount']/10000.0, 2); // 格式化结果保留两位小数
        //近一周的总金额
        // 获取本周的总金额
        $data['weeksale_allamount'] = Db::table('so_headers_all')
            ->where('creation_date', '>=', $thisWeekStart)
            ->where('creation_date', '<=', $thisWeekEnd)
            ->sum('order_all_amount');
        // 获取上一周的总金额
        $data['lastweeksale_allamount'] = Db::table('so_headers_all')
            ->where('creation_date', '>=', $lastWeekStart)
            ->where('creation_date', '<=', $lastWeekEnd)
            ->sum('order_all_amount');
        // 计算周涨幅比率
        if ($data['lastweeksale_allamount'] == 0) {
            $data['weekchangeRate'] = '无法计算';
        } else {
            $data['weekchangeRate'] = ($data['weeksale_allamount'] - $data['lastweeksale_allamount']) / $data['lastweeksale_allamount'] * 100;
            if ($data['weekchangeRate'] >= 0) {
                $data['weekchangeRate'] = '+' . number_format($data['weekchangeRate'], 2) . '%';
            } else {
                $data['weekchangeRate'] = number_format($data['weekchangeRate'], 2) . '%';
            }
            // $data['weekchangeRate'] = number_format(($data['weeksale_allamount'] - $data['lastweeksale_allamount']) / $data['lastweeksale_allamount'] * 100, 2) . '%';
        }
        $data['weeksale_allamount'] = number_format($data['weeksale_allamount']/10000.0, 2);
        // 获取本月的总金额
        $data['monthsale_allamount'] = Db::table('so_headers_all')
            ->where('creation_date', '>=', $thisMonthStart)
            ->where('creation_date', '<=', $thisMonthEnd)
            ->sum('order_all_amount');
        // 获取上一个月的总金额
        $data['lastmonthsale_allamount'] = Db::table('so_headers_all')
            ->where('creation_date', '>=', $lastMonthStart)
            ->where('creation_date', '<=', $lastMonthEnd)
            ->sum('order_all_amount');
        // 计算月涨幅比率
        if ($data['lastmonthsale_allamount'] == 0) {
           $data['monthchangeRate'] = '无法计算';
        } else {
            $data['monthchangeRate'] = ($data['monthsale_allamount'] - $data['lastmonthsale_allamount']) / $data['lastmonthsale_allamount'] * 100;
            if ($data['monthchangeRate'] >= 0) {
                $data['monthchangeRate'] = '+' . number_format($data['monthchangeRate'], 2) . '%';
            } else {
                $data['monthchangeRate'] = number_format($data['monthchangeRate'], 2) . '%';
            }
            // $data['monthchangeRate'] = number_format(($data['monthsale_allamount'] - $data['lastmonthsale_allamount']) / $data['lastmonthsale_allamount'] * 100, 2) . '%';
        }
        $data['monthsale_allamount'] = number_format($data['monthsale_allamount']/10000.0, 2);
        // 获取今年的总金额
        $data['yearsale_allamount'] = Db::table('so_headers_all')
            ->where('creation_date', '>=', $thisYearStart)
            ->where('creation_date', '<=', $thisYearEnd)
            ->sum('order_all_amount');
        // 获取去年的总金额
        $data['lastyearsale_allamount'] = Db::table('so_headers_all')
            ->where('creation_date', '>=', $lastYearStart)
            ->where('creation_date', '<=', $lastYearEnd)
            ->sum('order_all_amount');
        // 计算年涨幅
        if ($data['lastyearsale_allamount'] == 0) {
            $data['yearchangeRate'] = '无法计算';
        } else {
            $data['yearchangeRate'] = ($data['yearsale_allamount'] - $data['lastyearsale_allamount']) / $data['lastyearsale_allamount'] * 100;
            if ($data['yearchangeRate'] >= 0) {
                $data['yearchangeRate'] = '+' . number_format($data['yearchangeRate'], 2) . '%';
            } else {
                $data['yearchangeRate'] = number_format($data['yearchangeRate'], 2) . '%';
            }
            // $data['yearchangeRate'] = number_format(($data['yearsale_allamount'] - $data['lastyearsale_allamount']) / $data['lastyearsale_allamount'] * 100, 2) . '%';
        }
        $data['yearsale_allamount'] = number_format($data['yearsale_allamount']/10000.0, 2);
        //查询本周每天的的总金额数
        //获取本周的起始日期和结束日期
        $weekStart = date('Y-m-d', strtotime('this week Monday'));
        $weekEnd = date('Y-m-d', strtotime('this week Sunday'));
        // 构造日期范围数组(从周一到周天)
        $dateRange = [];
        $currentDate = $weekStart;
        while ($currentDate <= $weekEnd) {
            $dateRange[] = $currentDate;
            $currentDate = date('Y-m-d', strtotime($currentDate . ' +1 day'));
        }
        // 查询每天的总金额数
        $result = Db::table('so_headers_all')
            ->field("DATE_FORMAT(FROM_UNIXTIME(creation_date), '%Y-%m-%d') AS date, IFNULL(SUM(order_all_amount), 0) AS total_amount")
            ->whereTime('creation_date', '>=', $weekStart)
            ->whereTime('creation_date', '<=', $weekEnd)
            ->group('date')
            ->select();
        //去掉逗号,转换为
        foreach ($result as &$item) {
            $item['total_amount'] = round(($item['total_amount'] / 10000),2);
        }
        // 构造最终结果数组
        $dateArray = [];
        $totalAmountArray = [];
        foreach ($dateRange as $date) {
            $found = false;
            foreach ($result as $row) {
                if ($row['date'] == $date) {
                    $dateArray[] = $row['date'];
                    $totalAmountArray[] = $row['total_amount'];
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                $weekdayIndex = date('w', strtotime($date));
                $dateArray[] = $date;
                $totalAmountArray[] = 0;
            }
        }
        $data['week_info']['date'] = $dateArray;
        $data['week_info']['total_amount'] = $totalAmountArray;
        

        //查询今年中每月的总金额数据
        // 获取当前年份
        $year = date('Y');
        $result1 = Db::table('so_headers_all')
            ->field("DATE_FORMAT(FROM_UNIXTIME(creation_date), '%Y-%m') AS month, IFNULL(SUM(order_all_amount), 0) AS total_amount")
            ->whereTime('creation_date', '>=', strtotime($year . '-01-01'))
            ->whereTime('creation_date', '<=', strtotime($year . '-12-31'))
            ->group('month')
            ->select();
        //去掉逗号,转换为
        foreach ($result1 as &$item) {
            $item['total_amount'] = round(($item['total_amount'] / 10000),2);
        }
        // 构造最终结果数组
        $dateArray1 = [];
        $totalAmountArray1 = [];
        for ($i = 1; $i <= 12; $i++) {
            //str_pad 函数用于在字符串的左侧(或右侧)填充指定字符,达到指定长度。这里,使用 str_pad 函数在 $i 左侧填充字符 '0',直到 $i 的长度达到 2。
            $month = str_pad($i, 2, '0', STR_PAD_LEFT);
            $dateArray1[] = $year . '-' . $month;
            $totalAmountArray1[$year . '-' . $month] = 0;
        }
        // 将查询结果填充到对应的月份位置
        foreach ($result1 as $item) {
            $totalAmountArray1[$item['month']] = $item['total_amount'];
        }
        // 最终结果数组
        foreach ($dateArray1 as $date) {
            $finalResult[] = [
                'date' => $date,
                'total_amount' => $totalAmountArray1[$date]
            ];
            $data['month_info']['date'][] = $date;
            $data['month_info']['total_amount'][] = $totalAmountArray1[$date];
        }

        //查询近五年总金额数据
        // 获取当前年份
        $currentYear = date('Y');
        // 构造最终结果数组
        $data['year_info']['date'] = [];
        $data['year_info']['total_amount'] = [];
        
        for ($i = $currentYear - 5; $i <= $currentYear; $i++) {
            $year = (string) $i;
        
            $result = Db::table('so_headers_all')
                ->field("IFNULL(SUM(order_all_amount), 0) AS total_amount")
                ->whereTime('creation_date', '>=', strtotime($year . '-01-01'))
                ->whereTime('creation_date', '<=', strtotime($year . '-12-31'))
                ->find();
            $totalAmount = round(($result['total_amount'] / 10000), 2);
            $data['year_info']['date'][] = $year;
            $data['year_info']['total_amount'][] = $totalAmount;
        }
        echo json_encode($data);
    }

重写代码

<template>
	<view>
		<view>
			<view class="title">概况</view>
			<view class="line_position">
				<view class="line1">
					<view class="item">
						<view class="one">今日销售额(万元)</view>
						<view class="two">
							<view class="left">{{line1_info.daysale_allamount}}</view>
							<view class="right">{{line1_info.daychangeRate}}</view>
						</view>
						<view class="three">
							<image :src="getImagePath(line1_info.daychangeRate)" alt=""></image>
						</view>
					</view>
					<view class="item">
						<view class="one">本周销售额(万元)</view>
						<view class="two">
							<view class="left">{{line1_info.weeksale_allamount}}</view>
							<view class="right">{{line1_info.weekchangeRate}}</view>
						</view>
						<view class="three">
							<image :src="getImagePath(line1_info.weekchangeRate)" alt=""></image>
						</view>
					</view>
					<view class="item">
						<view class="one">本月销售额(万元)</view>
						<view class="two">
							<view class="left">{{line1_info.monthsale_allamount}}</view>
							<view class="right">{{line1_info.monthchangeRate}}</view>
						</view>
						<view class="three">
							<image :src="getImagePath(line1_info.monthchangeRate)" alt=""></image>
						</view>
					</view>
					<view class="item">
						<view class="one">今年销售额(万元)</view>
						<view class="two">
							<view class="left">{{line1_info.yearsale_allamount}}</view>
							<view class="right">{{line1_info.yearchangeRate}}</view>
						</view>
						<view class="three">
							<image :src="getImagePath(line1_info.yearchangeRate)" alt=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view>
			<view class="title">销售额统计</view>
			<view class="tab_position">
				<view class="tab-bar">
					<text class="tab" :class="{ 'active': activeTab === '0' }" @click="changeTab('0')">周统计</text>
					<text class="tab" :class="{ 'active': activeTab === '1' }" @click="changeTab('1')">月统计</text>
					<text class="tab" :class="{ 'active': activeTab === '2' }" @click="changeTab('2')">年统计</text>
				</view>
			</view>
			<view v-show="activeTab === '0'">
				<view class="out">
					<view :prop="option" :change:prop="echarts.updateEcharts" id="echarts" class="echarts"></view>
				</view>
			</view>
			<view v-show="activeTab === '1'">
				<view class="out">
					<view :prop="option1" :change:prop="echarts.updateEcharts1" id="echarts1" class="echarts"></view>
				</view>
			</view>
			<view v-show="activeTab === '2'">
				<view class="out">
					<view :prop="option2" :change:prop="echarts.updateEcharts2" id="echarts2" class="echarts"></view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	// import echarts from '@/static/js/echarts.js' // 引入文件
	import * as echarts from 'echarts';
	export default {
		data() {
			return {
				line1_info: '',
				down: getApp().globalData.icon + 'report/down.png',
				up: getApp().globalData.icon + 'report/up.png',
				line: getApp().globalData.icon + 'report/line.png',
				activeTab: '0', //默认分页面
				weekinfo: [], // 定义一个空数组用于存储周统计数据
				monthinfo: [], // 定义一个空数组用于存储月统计数据
				yearinfo: [], // 定义一个空数组用于存储年统计数据
				option: '',
				option1: '',
				option2: '',
			}
		},
		mounted() {
			this.getData(); // 在组件挂载后调用获取数据的方法
		},
		methods: {
			//切换分页面
			changeTab(index) {
				this.activeTab = index;
			},
			//图片展示
			getImagePath(rate) {
				if (rate === "无法计算") {
					return this.line;
				} else if (rate && rate.startsWith("-")) {
					return this.down;
				} else {
					return this.up;
				}
			},
			getData() {
				uni.request({
					url: getApp().globalData.position + 'Other/select_sale_ekanbaninfo',
					data: {},
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					method: 'POST',
					dataType: 'json',
					success: res => {
						//行1:年月日总额统计
						this.line1_info = res.data;
						//行2:周统计
						var weekinfo = res.data.week_info;
						this.weekinfo = weekinfo;
						//行2:月统计
						var monthinfo = res.data.month_info;
						this.monthinfo = monthinfo;
						//行2:年统计
						var yearinfo = res.data.year_info;
						this.yearinfo = yearinfo;
						// console.log(this.yearinfo)
						//显示图表
						this.echart();
					},
					fail(res) {
						console.log("查询失败")
					}
				});
			},
			//绘制图标
			echart() {
				// 周统计金额
				// 提取日期和对应的值
				var dates = this.weekinfo.date;
				var values = this.weekinfo.total_amount;
				var weeks = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"];
				// 进行图表的配置和数据处理
				this.option = {
					//配置网格组件,用于定义图表的位置和大小
					grid: {
						top: '15%', // 增加top的值来创建间距
						left: '2%',
						right: '2%',
						bottom: '2%', // 增加bottom的值来创建间距
						containLabel: true, //自动计算并包含坐标轴标签、刻度和标题等内容在内。
					},
					color: ['#e57b7b'],
					tooltip: {
						trigger: 'item',
						axisPointer: {
							type: 'line'
						},
						formatter: function(params) {
							var value = values[params.dataIndex];
							var date = dates[params.dataIndex];
							var week = weeks[params.dataIndex];
							var marker = params.marker; // 添加marker(小圆点)
							return marker + ' ' + date + '<br/>' + week + ' : ' + value + '万元';
						}
					},
					xAxis: {
						// name: '日期',
						data: weeks,
						axisLine: {
							show: false // 隐藏纵坐标轴的横线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					yAxis: {
						name: '金额(万元)',
						splitLine: {
							show: false // 隐藏纵坐标轴的背景横线
						},
						axisLine: {
							show: false // 隐藏纵坐标轴的竖线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						axisLabel: {
							fontSize: 12 // 设置横轴标签字体大小为12
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					series: [{
						barWidth: '8',
						name: '销量',
						type: 'bar',
						data: values,
						itemStyle: {
							normal: {
								label: {
									show: true,
									position: 'top',
									textStyle: {
										// color: '#515dc3',
										fontSize: 12
									}
								}
							}
						}
					}]
				};
				//月统计
				// 月统计金额
				// 提取日期和对应的值
				var dates1 = this.monthinfo.date;
				var values1 = this.monthinfo.total_amount;
				var months1 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
				var months1_chinese = ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"];
				// 进行图表的配置和数据处理
				this.option1 = {
					//配置网格组件,用于定义图表的位置和大小
					grid: {
						top: '15%', // 增加top的值来创建间距
						left: '2%',
						right: '2%',
						bottom: '2%', // 增加bottom的值来创建间距
						containLabel: true, //自动计算并包含坐标轴标签、刻度和标题等内容在内。
					},
					color: ['#5588d4'],
					tooltip: {
						trigger: 'item',
						axisPointer: {
							type: 'line'
						},
						formatter: function(params) {
							var value = values1[params.dataIndex];
							var date = dates1[params.dataIndex];
							var month = months1_chinese[params.dataIndex];
							var marker = params.marker; // 添加marker(小圆点)
							return marker + ' ' + date + '<br/>' + month + ' : ' + value + '万元';
						}
					},
					xAxis: {
						// name: '日期',
						data: months1,
						axisLine: {
							show: false // 隐藏纵坐标轴的横线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					yAxis: {
						name: '金额(万元)',
						splitLine: {
							show: false // 隐藏纵坐标轴的背景横线
						},
						axisLine: {
							show: false // 隐藏纵坐标轴的竖线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						axisLabel: {
							fontSize: 12 // 设置横轴标签字体大小为12
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					series: [{
						barWidth: '6',
						name: '销量',
						type: 'bar',
						data: values1,
						itemStyle: {
							normal: {
								label: {
									show: true,
									position: 'top',
									textStyle: {
										// color: '#515dc3',
										fontSize: 12
									}
								}
							}
						}
					}]
				};
				//近五年年统计
				// 年统计金额
				// 提取日期和对应的值
				var dates2 = this.yearinfo.date;
				var values2 = this.yearinfo.total_amount;
				// 进行图表的配置和数据处理
				this.option2 = {
					//配置网格组件,用于定义图表的位置和大小
					grid: {
						top: '15%', // 增加top的值来创建间距
						left: '2%',
						right: '2%',
						bottom: '2%', // 增加bottom的值来创建间距
						containLabel: true, //自动计算并包含坐标轴标签、刻度和标题等内容在内。
					},
					color: ['#71aa77'],
					tooltip: {
						trigger: 'item',
						axisPointer: {
							type: 'line'
						},
						formatter: function(params) {
							var value = values2[params.dataIndex];
							var date = dates2[params.dataIndex];
							var marker = params.marker; // 添加marker(小圆点)
							return marker + ' ' + date + '年' + '<br/>' + value + '万元';
						}
					},
					xAxis: {
						// name: '日期',
						data: dates2,
						axisLine: {
							show: false // 隐藏纵坐标轴的横线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					yAxis: {
						name: '金额(万元)',
						splitLine: {
							show: false // 隐藏纵坐标轴的背景横线
						},
						axisLine: {
							show: false // 隐藏纵坐标轴的竖线
						},
						//隐藏小刻度短线
						axisTick: { // x轴刻度相关配置
							show: false, // 是否显示x轴刻度线
						},
						axisLabel: {
							fontSize: 12 // 设置横轴标签字体大小为12
						},
						nameTextStyle: {
							fontSize: 12 // 设置横轴名称字体大小为12
						}
					},
					series: [{
						barWidth: '8',
						name: '销量',
						type: 'bar',
						data: values2,
						itemStyle: {
							normal: {
								label: {
									show: true,
									position: 'top',
									textStyle: {
										// color: '#515dc3',
										fontSize: 12
									}
								}
							}
						}
					}]
				}
			},
		},
	}
</script>
<!-- 指定脚本类型模块为echarts,语言为renderjs -->
<script module="echarts" lang="renderjs">
	let myChart
	let myChart1
	let myChart2
	export default {
		mounted() {
			// 首先判断window.echarts是否存在,如果存在则调用initEcharts1方法进行初始化。
			if (typeof window.echarts === 'function') {
				this.initEcharts()
				this.initEcharts1()
				this.initEcharts2()
			} else {
				// 如果不存在,则动态创建一个<script>标签,并设置其src属性为static/js/echarts.js,然后在加载完成后调用initEcharts方法。
				// 动态引入较大类库避免影响页面展示
				const script = document.createElement('script')
				script.src = 'static/js/echarts.js'
				script.onload = function() {
					this.initEcharts()
					this.initEcharts1()
					this.initEcharts2()
				}.bind(this)
				document.head.appendChild(script)
			}
		},
		methods: {
			initEcharts() {
				myChart = echarts.init(document.getElementById('echarts'))
			},
			initEcharts1() {
				myChart1 = echarts.init(document.getElementById('echarts1'))
			},
			initEcharts2() {
				myChart2 = echarts.init(document.getElementById('echarts2'))
			},
			updateEcharts(newValue, oldValue, ownerInstance, instance) {
				if (myChart != undefined) {
					myChart.setOption(newValue)
				}
			},
			updateEcharts1(newValue, oldValue, ownerInstance, instance) {
				if (myChart1 != undefined) {
					myChart1.setOption(newValue)
				}
			},
			updateEcharts2(newValue, oldValue, ownerInstance, instance) {
				if (myChart2 != undefined) {
					myChart2.setOption(newValue)
				}
			},
		}
	}
</script>
<style lang="scss">
	//第一行内容
	.title {
		// border:1px solid black;
		padding-left: 2%;
		font-size: 105%;
	}

	.line_position {
		overflow-x: scroll;
		scroll-behavior: smooth; // 设置滚动平滑过渡

		//隐藏滚动条
		&::-webkit-scrollbar {
			width: 0; // 隐藏默认的滚动条 
			height: 0;
		}

		&::-webkit-scrollbar-thumb {
			background-color: transparent; // 隐藏滚动条拖拽的小方块
		}

		.line1 {
			width: 400%;
			display: flex;

			// border:1px solid red;
			.item:nth-child(1) {
				background-color: #515dc3;
			}

			.item:nth-child(2) {
				background-color: #ff9a3e;
			}

			.item:nth-child(3) {
				background-color: #38bf80;
			}

			.item:nth-child(4) {
				background-color: #fc5959;
			}

			.item {
				width: 40%;
				margin: 1% 2%;
				border-radius: 5px;
				padding: 1% 1% 0 1%;
				// border:1px solid red;
				color: white;

				.two {
					display: flex;
					margin: 5% 0;
					align-items: center;

					// border:1px solid red;
					.left {
						width: 70%;
						font-size: 24px;
						// border:1px solid red;
					}

					.right {
						text-align: right;
						width: 30%;
						// border:1px solid red;
					}
				}

				.three {
					text-align: center;

					// border:1px solid red;
					image {
						width: 60px;
						height: 50px;
					}
				}
			}
		}
	}

	//第二行内容
	.tab_position {
		width: 100%;
		display: flex;
		justify-content: center;
	}

	.tab-bar {
		display: flex;
		justify-content: space-between;
		width: 90%;
		// border: 1px solid black;
		background-color: #f2f2f2;
		border-radius: 15px;
		margin: 3% 1%;
	}

	.tab {
		padding: 5px;
		font-size: 16px;
		cursor: pointer;
		// border: 1px solid black;
		width: 33%;
		text-align: center;
		// border-bottom: 1px solid #ccc;
	}

	.active {
		color: white;
		background-color: #515dc3;
		border-radius: 15px;
		/* background-color:#74bfe7; */
		// border-bottom: 1px solid #74bfe7;
	}

	//图标
	.out {
		width: 100%;
		display: flex;
		justify-content: center;
	}

	.echarts{
		width: 700rpx;
		height: 600rpx;
	}
</style>

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1072109.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

公众号突破注册操作流程

一般可以注册多少个公众号&#xff1f;众所周知&#xff0c;在2013年前后&#xff0c;公众号申请是不限制数量的&#xff0c;后来企业开始限制申请50个&#xff0c;直到2018年的11月tx又发布&#xff0c;其中个人主体可申请公众号由2个调整为1个&#xff0c;企业主体由50个调整…

Java中树形菜单的实现方式(超全详解!)

前言 这篇文中&#xff0c;我一共会用两种方式来实现目录树的数据结构&#xff0c;两种写法逻辑是一样的&#xff0c;只是一种适合新手理解&#xff0c;一种看着简单明了但是对于小白不是很好理解。在这里我会很详细的讲解每一步代码&#xff0c;主要是方便新人看懂&#xff0…

北邮22级信通院数电:Verilog-FPGA(5)第四第五周实验 密码保险箱的设计

北邮22信通一枚~ 跟随课程进度更新北邮信通院数字系统设计的笔记、代码和文章 持续关注作者 迎接数电实验学习~ 获取更多文章&#xff0c;请访问专栏&#xff1a; 北邮22级信通院数电实验_青山如墨雨如画的博客-CSDN博客 目录 一.密码箱的功能和安全性 显示&#xff1a;…

Qt 对界面类重命名的步骤

有些时候因为一些原因&#xff0c;需要修改Qt中创建的界面类&#xff0c;修改的地方比较多&#xff0c;一定要留意有没有修改完全&#xff0c;否则会出现各种奇怪报错。 比如&#xff0c;将MainWindow界面类名修改为lb_logdisplay 修改步骤&#xff1a; 修改文件名&#xff1a;…

【Redis】字符串类型命令

目录 字符串类型命令SETGETMGETSETNXINCRINCRBYDECRDECYBYINCRBYFLOATAPPENDGETRANGESETRANGESTRLEN 字符串类型命令 SET 将string类型的value设置到key中。如果key之前存在&#xff0c;则覆盖&#xff0c;⽆论原来的数据类型是什么。之前关于此key的TTL也全部失效。 SET key…

一文拿捏线程池

1 谈谈你对线程池理解 1 概念 线程池是一种用于管理线程的机制&#xff0c;核心思想是资源复用&#xff0c;避免频繁地创建和销毁线程所带来的性 能开销。 2 原理 线程池的原理是预先创建一定数量的线程&#xff0c;并将它们放入一个线程池中。当有任务需要执行时&#xff0…

人工智能(AI)技术的实际应用

人工智能&#xff08;AI&#xff09;技术在各个领域都有广泛的实际应用。这些示例只是AI技术的一小部分应用&#xff0c;AI正在不断演化中。以下是一些常见的实际AI应用示例&#xff0c;希望对大家有所帮助。北京木奇移动技术有限公司&#xff0c;专业的软件外包开发公司&#…

动态内存管理之经典笔试题

目录 C/C程序的内存开辟 题目1 题目2 题目3 题目4 今天我们来接着讲几道经典的笔试题。首先来了解一下c\c程序的内存开辟&#xff0c;使我们做题的头脑更加清晰。 C/C程序的内存开辟 内核空间 是用户代码不能读写的栈区是用来开辟 局部变量 形式参数&#xff0c;函数栈…

0基础学python,给大家首推这些书!

对于0基础的人来说&#xff0c;学习Python首推的书就是这本 《Python 编程&#xff1a;从入门到实践》 。 这本书常居各网站编程图书销量榜第一名&#xff0c;目前在全球范围内被翻译成 12 国语言&#xff0c;仅在中国就帮助了超过 120 万对 Python 有需求的学习者入门&#x…

【华为OD机考B卷 | 100分】五子棋迷(JAVA题解——也许是全网最详)

前言 本人是算法小白&#xff0c;甚至也没有做过Leetcode。所以&#xff0c;我相信【同为菜鸡的我更能理解作为菜鸡的你们的痛点】。 题干 1. 题目描述 张兵和王武是五子棋迷&#xff0c;工作之余经常切磋棋艺。走了一会儿&#xff0c;轮到张兵了&#xff0c;他对着一条线思…

Vue CLI和Vite区别

1.Vue CLI脚手架 什么是Vue脚手架&#xff1f; 在真实开发中我们不可能每一个项目从头来完成所有的webpack配置&#xff0c;这样显示开发的效率会大大的降低&#xff1b;所以在真实开发中&#xff0c;我们通常会使用脚手架来创建一个项目&#xff0c;Vue的项目我们使用的就是…

在线世界各国语言翻译器

最近失业&#xff0c;无聊之极&#xff0c;想着搞点啥东西&#xff0c;一上午撸了一个世界各国语言跟汉语的互相翻译的功能&#xff0c;提供的语言列表无所不包含&#xff0c;这里列一下给大家看看&#xff0c;算了语言列表实在太长了&#xff0c;我还是把界面先放前面吧, 对的…

vue-5

一、文章内容概括 1.自定义指令 基本语法&#xff08;全局、局部注册&#xff09;指令的值v-loading的指令封装 2.插槽 默认插槽具名插槽作用域插槽 3.综合案例&#xff1a;商品列表 MyTag组件封装MyTable组件封装 4.路由入门 单页应用程序路由VueRouter的基本使用 二…

常用求解器安装

1 建模语言pyomo Pyomo是一个Python建模语言&#xff0c;用于数学优化建模。它可以与不同的求解器&#xff08;如Gurobi&#xff0c;CPLEX&#xff0c;GLPK&#xff0c;SCIP等&#xff09;集成使用&#xff0c;以求解各种数学优化问题。可以使用Pyomo建立数学优化模型&#xf…

笔试强训选择题

欢迎来到Cefler的博客&#x1f601; &#x1f54c;博客主页&#xff1a;那个传说中的man的主页 &#x1f3e0;个人专栏&#xff1a;题目解析 &#x1f30e;推荐文章&#xff1a;题目大解析&#xff08;3&#xff09; 目录 &#x1f449;&#x1f3fb;Day7 &#x1f449;&#x…

抖音seo源码开发部署市场分析及注意事项分享---SaaS开源

抖音seo源码开发部署市场背景分析 对于抖音SEO源码开发部署的背景分析&#xff0c;可以从以下几个方面来展开&#xff1a; 抖音平台的发展和趋势&#xff1a;随着移动互联网的快速发展&#xff0c;抖音作为短视频领域的领军企业&#xff0c;其用户规模和市场规模也在不断扩大。…

2023年中国电容炭受益于超级电容器需求及进口替代双重驱动,行业呈快速增长态势[图]

电容炭是目前在超级电容器领域实现商业化应用的最为主要的电极材料。电容炭具有“三高三低”的优势&#xff0c;即高比表面积、高孔容、高电导率、低灰分、低金属离子、低粒径&#xff0c;是超级电容电极的核心材料。 电容炭是超级电容器的电极材料。电容炭指标关系着超级电容器…

Vue 识别移动设备还是PC设备跳转相应的路由

1. 先在router/index.js文件中配置好不同端口跳转的路由 import Vue from vue import VueRouter from vue-router// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题 const originalPush VueRouter.prototype.push VueRouter.prototype.push function pu…

GitHub要求开启2FA,否则不让用了。

背景 其实大概在一个多月前&#xff0c;在 GitHub 网页端以及邮箱里都被提示&#xff1a;要求开启 2FA &#xff0c;即双因子认证&#xff1b;但是当时由于拖延症和侥幸心理作祟&#xff0c;直接忽略了相关信息&#xff0c;毕竟“又不是不能用”。。 只到今天发现 GitHub 直接…

超越日历的智慧:探索节日节气、宜忌和星座生肖等信息的万年历API

引言 当今社会&#xff0c;人们对时间的需求不仅仅是简单地知道日期&#xff0c;更多地是追求个性化、文化化和精确化的时间信息。在这个背景下&#xff0c;万年历API变得越来越重要&#xff0c;因为它可以提供超越传统日历的智慧&#xff0c;为我们带来了丰富的日期信息&…