2020-08-26

自定义echarts横向条形图

在这里插入图片描述

                                        这里是实际的效果图
<html>
//这里是html页面,只有一个画布,和一些引用文件
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no,viewport-fit=cover" />
		<link rel="stylesheet" href="./css/series/mybar.css" />
		<link rel="stylesheet" href="./css/base.css" />
		<script src="./js/echarts.min.js"></script>
	</head>
	<body>
		<div id="app">
			<div id="main"></div>
		</div>
		<script type="text/javascript" src="./js/vue.js"></script>
		<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
		<script src="./js/series/mybar.js"></script>
	</body>
</html>
//在vue中使用的时候,注意对画布的操作要写在methods中,然后在mounted()挂载,而不是在created()进行初始化。具体的样式属性可以去Echarts官方文档查找。https://echarts.apache.org/zh/index.html
const _vue=new Vue({
	el:"#app",
	data:{
		yAxisData:['安阳学院', '驻马店学院', '平顶山学院', '新乡学院', '郑州学院'],
		seriesOne:[182, 234, 290, 104, 131],
		seriesTwo:[193, 234, 310, 121, 134],
		seriesThree:[169, 133, 230, 161, 136]
		
		
	},
	methods:{
		showEcharts(){
			var myChart = echarts.init(document.getElementById('main'));
			
			option = {
				title: {
					text: '近三十天院校数据(开发)',
					textStyle: {
						color: '#335ec3',
						fontSize: 14
					},
					top: 40
				},
				tooltip: {
					trigger: 'axis',
					axisPointer: {
						type: 'shadow'
					}
				},
				legend: {
					textStyle: {
						color: '#ffffff'
					},
					data: [{
							name: '大一',
							icon: 'rect',
							textStyle: {
								color: '#ffffff'
							}
						},
						{
							name: '大二',
							icon: 'rect',
							textStyle: {
								color: '#ffffff'
							}
						},
						{
							name: '大三',
							icon: 'rect',
							textStyle: {
								color: '#ffffff'
							}
						}
					],
					icon: 'rect',
					selected: {
						'大二': false,
						'大三': false
					},
					selectedMode: 'single',
					left: 200,
					top: 40
			
				},
				grid: {
					y: 80,
					y2: 30,
					left: '3%',
					right: '4%',
					bottom: '3%',
					containLabel: true,
					width: 400
				},
				xAxis: {
					type: 'value',
					boundaryGap: [0, 0.02],
					splitLine: {
						show: false
					},
					max: 400,
			
					//横轴的样式
					axisLine: {
						show:false,
						lineStyle: {
							color: "#bfbfbf"
						}
					}
					/* 网格样式
						splitLine:{
							show:true,
							lineStyle:{
								color:['#262732'],
								width:1,
								type:'solid'
							}
						} */
			
				},
				yAxis: {
					type: 'category',
					data:this.yAxisData ,
					splitLine: {
						show: false
					},
					axisLine: {
						show:false,
						lineStyle: {
							color: "#bfbfbf"
						}
					}
					/* 网格样式
					 splitLine:{
					  	show:true,
					  	lineStyle:{
					  		color:['#262732'],
					  		width:1,
					  		type:'solid'
					  	}
					  } */
				},
				series: [{
						name: '大一',
						type: 'bar',
						data:this.seriesOne,
						barWidth: 15,
						itemStyle: {
							color: '#d3424b',
							barBorderRadius: [10, 10, 10, 10],// (顺时针左上,右上,右下,左下)
							borderColor:'#aa55ff',
							borderWidth:2
			
						},
						showBackground: true,
						backgroundStyle: {
							color: '#15172a',
							barBorderRadius: [10, 10, 10, 10],
							shadowColor: '#eb40a1',
							shadowBlue: 50,
							shadowOffsetX: 0,
							shadowOffsetY: 0.1
						}
					},
					{
						name: '大二',
						type: 'bar',
						data:this.seriesTwo ,
						barWidth: 15,
						itemStyle: {
							color: '#d3424b',
							barBorderRadius: [10, 10, 10, 10], // (顺时针左上,右上,右下,左下)
							shadowColor: '#eb40a1',
							shadowBlue: 10,
							borderColor:'#aa55ff',
							borderWidth:2
						},
						showBackground: true,
						backgroundStyle: {
							color: '#15172a',
							barBorderRadius: [10, 10, 10, 10],
							shadowColor: '#eb40a1',
							shadowBlue: 50,
							shadowOffsetX: 0,
							shadowOffsetY: 0.3
						}
			
					},
					{
						name: '大三',
						type: 'bar',
						data:this.seriesThree ,
						barWidth: 15,
						itemStyle: {
							color: '#d3424b',
							barBorderRadius: [10, 10, 10, 10], // (顺时针左上,右上,右下,左下)
							shadowColor: '#eb40a1',
							shadowBlue: 10,
							borderColor:'#aa55ff',
							borderWidth:2
						},
						showBackground: true,
						backgroundStyle: {
							color: '#15172a',
							barBorderRadius: [10, 10, 10, 10],
							shadowColor: '#eb40a1',
							shadowBlue: 50,
							shadowOffsetX: 0,
							shadowOffsetY: 0.3
						}
					}
				]
			};
			myChart.setOption(option);
			
		}
	},
	mounted() {
		this.showEcharts();
	}
})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值