echarts柱状图案列及效果

news/2024/7/24 5:00:59 标签: css, 数据可视化, 其他

下面echarts 柱状图

首先效果图
在这里插入图片描述
下面开始堆代码

1、先看一下vue中html

<template>
	<view class="content">
		<!-- 标题描述 - 标题总数显示 -->
		<view class="describe">
			<view class="describeL">
				<view class="circle"></view>
				<text>投入金额</text>
				<text>220亿</text>
			</view>
			<view class="describeR">
				<view class="circle"></view>
				<text>资产规模</text>
				<text>36545亿</text>
			</view>
        </view>
		<!-- 图表-柱状图 -->
		<view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="histogram" class="echarts"></view>
	</view>
</template>

2.javascript里面配置

<script>
	export default {
		props: {
			dataListX: {
				type: Array,
				default: () => [],
			},
			dataList: {
				type: Array,
				default: () => [],
			},
			operationData:{
				type:Object,
				default:{} 
			}
		},
		data() {
			return {
				echartKey:1,
			}
		},
		computed:{
			option(){
				return {
					grid: {
                            x:30,
							y:10,
							x2:20,
							y2:40,
							left:40,
							right:12
                           },
					tooltip: {
						trigger: 'axis',
						axisPointer: { // 坐标轴指示器,坐标轴触发有效
							type: 'shadow', // 默认为直线,可选为:'line' | 'shadow'
							shadowStyle: { // 阴影指示器样式设置
								width: 'auto', // 阴影大小
								color: {
											type: 'linear',
											x: 0,
											y: 0,
											x2: 0,
											y2: 1,
											colorStops: [{
												offset: 0,
												color: 'rgba(211, 177, 150, 0.5)' // 0% 处的颜色
											}, {
												offset: 1,
												color: 'rgba(179, 119, 72, 0)' // 100% 处的颜色
											}],
											globalCoord: false // 缺省为 false
									} // 阴影颜色
							}
						}
					},
					xAxis: {
						type: 'category',
						data: this.dataListX,
						axisLabel: { //字体
							interval: 0,
							textStyle: {
								color: '#B4B6BC'
							}
						},
						axisLine: { //线条						
							lineStyle: {
								color: '#E4E8ED',
							}
						},
						axisTick: {
							show: false
						}
					},
					yAxis: {
						type: 'value',
						scale : true,
						max : 300,
						min : 0,
						splitNumber : 3,
						boundaryGap : [ 0.2, 0.2 ],
						//设置网格线颜色
						 splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(172, 191, 221, .11)',
                                    width: 1,
                                    type: 'solid'
                                }
                            },
						axisTick: {
							show: false
						},
						axisLabel: {
							textStyle: {
								color: '#E4E8ED'
							}
						},
						axisLine: {
							lineStyle: {

								color: '#FFFFFF',
							}
						},
					},
					series: [{
							name: '投入金额',
							type: 'bar',
							barWidth:8,
							data: [2, 2, 4, 7, 16, 17, 20, 26, 26, 38, 29, 33],
							emphasis: {
								focus: 'series'
							},
							itemStyle: {
								normal: {
									barBorderRadius: [2, 2, 0, 0],
									color: {
										type: 'linear',
										x: 0,
										y: 0,
										x2: 0,
										y2: 1,
										colorStops: [{
											offset: 0,
											// rgba(210, 153, 86, 0.4)
											color: '#D29956' // 0% 处的颜色
										}, {
											offset: 1,
											// rgba(154, 79, 29, 0.1)
											color: '#9A4F1D' // 100% 处的颜色
										}],
										globalCoord: false // 缺省为 false
									},
								},

							},
						},
						{
							name: '资产规模',
							type: 'bar',
							barWidth:8,
							data: [3114, 3057, 3102, 3082, 3159, 3170, 3105, 3009, 3160, 3146, 2757, 2684],
							itemStyle: {
								normal: {
									//设置圆角
									barBorderRadius: [2, 2, 0, 0],
									color: {
										type: 'linear',
										x: 0,
										y: 0,
										x2: 0,
										y2: 1,
										colorStops: [{
											offset: 0,
											// rgba(210, 153, 86, 1)
											color: 'rgba(210, 153, 86, .4)' // 0% 处的颜色
										}, {
											offset: 1,
											// rgba(154, 79, 29, 1)
											color: 'rgba(154, 79, 29, .4)' // 100% 处的颜色
										}],
										globalCoord: false // 缺省为 false
									}
								}
							},
						}
					]
				}
			}
		},
		methods: {
		}
	}
</script>

<script module="echarts" lang="renderjs">
	let myChart
	export default {
		name: 'histogram',
		mounted() {
		var timer =	setTimeout(() => {
			if (typeof window.echarts === 'function') {
				this.initEcharts()
			} else {
				// 动态引入较大类库避免影响页面展示
				const script = document.createElement('script')
				// view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
				script.src = 'static/echarts.js'
				script.onload = this.initEcharts.bind(this)
				document.head.appendChild(script)
			}
				clearTimeout(timer)
			}, 1000);
			
		},
		methods: {
			initEcharts() {
				myChart = echarts.init(document.getElementById('histogram'))
				// 观测更新的数据在 view 层可以直接访问到
				myChart.setOption(this.option)
			},
			updateEcharts(newValue, oldValue, ownerInstance, instance) {
				// 监听 service 层数据变更
				if (this.dataList.length > 0) {
					myChart.setOption(newValue)
				}
			},
		}
	}
</script>

css_241">3css代码

css"><style lang="less" scoped>
.title{
	font-size: 32rpx;
	font-family: PingFangSC-Semibold, PingFang SC;
	font-weight: 600;
	color: #2E313C;
	padding: 0rpx 30rpx;
	margin-top: 42rpx;
}
.wrapper{padding: 0rpx 30rpx 80rpx;margin-top: 20rpx;
	.content{
        height: 450rpx;
		background: #FFFFFF;
		box-shadow: 0px 6px 18px 0px rgba(70, 66, 61, 0.1);
		border-radius: 12rpx;
		border: 1px solid rgba(220, 218, 213, .2);
	}
}
</style>

↓↓↓ 个人写的一个公众号,还在完善中 ,欢迎加入↓↓↓ | ᴥ•́ )✧ ↓↓↓

在这里插入图片描述


http://www.niftyadmin.cn/n/1728093.html

相关文章

Python学习:字典和集合,真的了解吗?

Python除了列表和元组还有两个很常见并且很有用的数据结构&#xff1a;字典&#xff08;dict&#xff09;和集合&#xff08;set&#xff09;。字典和集合在 Python 被广泛使用&#xff0c;并且性能进行了高度优化&#xff0c;故是非常重要的。 注&#xff1a;笔记来源于景霄老…

echarts父组件向子组件传值报错

对于echarts 一直都是云里雾里 开发时候碰到一个问题一直在那儿倒腾&#xff0c;最后九牛二虎再加外圈刮&#xff0c;摸索出来了 先上图看报错 好家伙 本以为一切都好了 没想到控制台报错了。对于这个错一直蒙状态 审视代码于是发现是数据问题&#xff0c;查阅了官网及各种…

Python学习:字符串的深入浅出

字符串是python很常见的一种数据类型&#xff0c;比如日志的打印&#xff0c;程序中函数的注释&#xff0c;数据库的访问&#xff0c;变量的操作都需要用到字符串。 一、字符串基础 字符串是由独立字符组成的一个序列&#xff0c;通常包含在单引号&#xff08;’’&#xff0…

echarts对Y轴坐标控制

echarts自定义y轴刻度信息 <!DOCTYPE html> <html> <head><meta charset"utf-8"><title>ECharts</title><!-- 引入 echarts.js --><script src"echarts.common.min.js"></script> </head> &…

Python学习:输入输出--”黑箱“

本博客记录的是对Python输入输出的一个简单学习。 一、输入输出基础 最简单直接的输入来自键盘操作&#xff0c;如下&#xff1a; name input(your name:) gender input(you are a boy?(y/n))###### 输入 ###### your name:zhu you are a boy?ywelcome_str Welcome to …

uni-app原生导航栏自定义图标及去掉图标

uni-app自定义原生导航栏 下面是部分代码并不是完整的,这里只用作引子 { //人员对比详情"path": "personnel-panorama-contrast/index","style": {"navigationBarTitleText": "人员对比详情","app-plus": {&qu…

MySQL学习:事务的隔离

简单来说&#xff0c;事务就是要保证一组数据库操作&#xff0c;要么全部成功&#xff0c;要么全部失败。在 MySQL 中&#xff0c;事务支持是在引擎层实现的。MySQL 是一个支持多引擎的系统&#xff0c;但并不是所有的引擎都支持事务。比如 MySQL 原生的 MyISAM 引擎就不支持事…

UNI-APP 生成APP如何获取应用签名和应用包名称

UNI-APP 生成APP 微信支付和登录&#xff0c;都需要移动应用,是在微信公众开放平台中申请移动应用 https://open.weixin.qq.com/cgi-bin/index?thome/index&langzh_CN 一、申请过程中&#xff0c;苹果应用要申请苹果APPID 这个需要在苹果开发者申请成为开发者&#xff0c…