自定义柱状图-条状图——不同区间值,显示不同颜色

自定义柱状图-条状图——不同区间值,显示不同颜色

效果

在这里插入图片描述

代码

index.vue

<template>
	<div class="rightArea-box">
		<div class="top">
			<titleHeader :title="titleTop" />
			<div class="top-data">
				<div ref="echartsRef" class="content-box"></div>
			</div>
		</div>
		<div class="bottom">
			<titleHeader :title="titleBottom" />
			<div class="bottom-data">
				<div class="bottom-data-item" v-for="(item, index) in deviceList" :key="index">
					<label>{{ item.title }}</label>
					<b :style="bottomItemStyle(item)"></b>
					<span v-if="item.days === 0">不可继续使用</span>
					<span v-else-if="item.days > 0 && item.days <= 10">剩余{{ item.days }}天</span>
					<span v-else-if="item.days > 10 && item.days <= 20">剩余{{ item.days }}天</span>
					<span v-else-if="item.days > 20 && item.days <= 30">剩余{{ item.days }}天</span>
					<span v-else-if="item.days > 30 && item.days < 180">剩余{{ item.days }}天</span>
					<span v-else-if="item.days == 180">剩余{{ item.days }}天</span>
					<span v-else>大于180天</span>
				</div>
			</div>
		</div>
	</div>
</template>
<script setup lang="ts" name="rightArea">
import titleHeader from "@/components/header/titleHeader.vue";
import { ref, onMounted } from "vue";
const titleBottom = ref("设备剩余寿命排行");
const deviceList = ref([
	{ title: "特别备用1号风机", days: 0 },
	{ title: "特别备用2号风机", days: 8 },
	{ title: "1号风机", days: 18 },
	{ title: "2号风机", days: 28 },
	{ title: "3号风机", days: 90 },
	{ title: "4号风机", days: 120 },
	{ title: "5号风机", days: 180 },
	{ title: "6号风机", days: 180 },
	{ title: "7号风机", days: 180 },
	{ title: "8号风机", days: 180 },
	{ title: "9号风机", days: 180 },
	{ title: "10号风机", days: 180 },
	{ title: "11号风机", days: 180 },
	{ title: "12号风机", days: 280 }
]);
const bottomItemStyle = (item: any) => {
	if (item.days === 0) {
		return { background: "#ff5d5d", width: "20%" };
	} else if (item.days > 0 && item.days <= 10) {
		return { background: "#FF7D7D", width: "20%" };
	} else if (item.days > 10 && item.days <= 20) {
		return { background: "#FF8E8E", width: "20%" };
	} else if (item.days > 20 && item.days <= 30) {
		return { background: "#FFAEAE", width: "20%" };
	} else if (item.days > 30 && item.days < 180) {
		// 百分比范围 20% --- 60%
		// ((当前天数 - 最低30天) / (180 - 30) / 100 ) * 可用的百分比 50% + 前面30所占得百分比 20%
		return { background: "#00F0FF", width: ((item.days - 30) / 1.5) * 0.5 + 20 + "%" };
	} else {
		return { background: "#00FFBB", width: "70%" };
	}
};

onMounted(() => {});
</script>
<style scoped lang="scss">
.rightArea-box {
	display: flex;
	flex-flow: column;
	width: 100%;
	padding-bottom: 10px;

	.bottom {
		flex: 1;
	}
}

.bottom-data {
	height: calc(100% - 20px);
	max-height: 300px;
	overflow: auto;
	display: flex;
	flex-flow: column;
	.bottom-data-item {
		// 保障flex下元素宽度不变
		flex-grow: 0;
		flex-shrink: 0;
		display: flex;
		margin: 5px 0;
		padding: 0 24px;
		align-items: center;
		> label {
			color: #adb9c7;
			font-size: 14px;
			text-align: right;
			width: 80px;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}
		> b {
			display: inline-block;
			height: 14px;
			border-radius: 4px;
			margin: 0 5px;
		}
		> span {
			color: #ffffff;
			font-size: 14px;
		}
	}
}
</style>
title组件

src\components\header\titleHeader.vue

<template>
	<div class="header-container">
		<div class="title-img">
			<!-- title文字 -->
			<span>{{ props.title }}</span>
			<!-- title单选 -->
			<slot name="right"></slot>
			<!-- title图片 -->
			<img @click="isDialog" class="header" :src="props.src" v-show="props.src != ''" />
		</div>
		<div class="mark">
			<slot name="mark" />
		</div>
	</div>
</template>

<script lang="ts" setup>
const props = defineProps({
	src: {
		type: String,
		required: false,
		default: ""
	},
	title: {
		type: String,
		required: true,
		default: ""
	}
});

// 展示弹框
const emit = defineEmits(["is-dialog"]);
const isDialog = () => {
	emit("is-dialog", "");
};
</script>

<style lang="scss" scoped>
.header-container {
	padding: 24px 24px 6px;
	.title-img {
		display: flex;
		font-family: "PingFang SC";
		font-size: 22px;
		color: rgb(255 255 255 / 100%);
		align-items: center;
		> span {
			margin-right: auto;
		}
		> img {
			cursor: pointer;
			margin-left: 24px;
			height: 20px;
		}
	}
}
</style
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值