我的代码:异形图柱状图-echarts(柱子顶部自定义图形:pictorialBar实现)

1,302 阅读1分钟

这个用的是图片直接定位在顶部,今天发现可以用symbolRotate旋转,具体可以看看下面的这个demo gallery.echartsjs.com/editor.html… 文档地址:echarts.apache.org/zh/option.h…

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>柱图-横向</title>
		<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
		<script src="./js/echarts.js"></script>
		<style>
			body{
				background:rgb(8,13,47)
			}
			.echarts{
				width:500px;
				height: 500px;
				border:1px solid white
			}
		</style>
	</head>
	<body>
		<div class="echarts" id="demo"></div>
	</body>
	<script>
		window.onload=function(){
			init({
				_id:'demo',
				_categoryData:['轨道交通','航空装备','节能环保','新材料','新能源','新一代信息','新医药及生','智能电网'],
				_data:[80,70,55,67,79,37,89,43]
			})
		}
		function init(params){
			let {_id,_categoryData,_data} = params;
			let myChart = echarts.init(document.getElementById(_id));
			let option = {
			    color: '#0febff',
			    grid: {
			    	containLabel:true,
			    	left:'4%',
			    	bottom:'8%',
			    	right:'5%',
			    	top:'7%'
			    },
			    legend: {
			    	show:false,
			        right:'3%',
			        bottom:'8%',
			        itemWidth:20,
			        orient:'vertical',
			        itemGap:16,
			        textStyle:{
			        	color:'white',
			        	fontSize:14
			        }
			    },
			    xAxis:[{
			    	axisLine: {
		                show:false
		            },
		            axisTick: {
		                show: false
		            },
		            splitLine: {
		                show: true,
		                lineStyle:{
		                	color:'#7dd1d4',
		                	opacity:0.4,
		                	type:'dashed'
		                }
		            },
		            axisLabel:{
		            	interval:0,
		            	fontSize:16,
		            	color:'white'
		            }
			    }],
			    yAxis:[{
			    	data:_categoryData,
			    	position: 'left',
			        axisLabel: {
			        	color: '#fff',
	                    fontSize: 16,
			        },
			        axisTick: {
			            show: false
			        },
			        axisLine: {
			            show: true,
			            lineStyle: {
			                color: '#7dd1d4'
			            }
			        },
			        splitLine: {
			            show: false,
			        }
			    }],
			    series: [{
			        name: '',
			        type: 'bar',
			        barWidth:17,
		        	itemStyle:{
		        		color:new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
			                    offset: 0,
			                    color: 'rgba(15,235,255,0)'
			                },
			                {
			                    offset: 1,
			                    color: 'rgba(15,235,255,0.6)'
			                }
			            ]),
		        		opacity:0.6
		        	},
			        data:_data
			    },{
			    	type: 'pictorialBar',
			    	symbol: 'image://./img/skew.png',
			        symbolSize: [17, 17],
			        symbolOffset: [0, 0],
			        symbolPosition: 'end',
			        z: 12,
			        itemStyle: {
			            normal: {
			                color: '#14b1eb'
			            }
			        },
			        data:_data
			    }]
			}
			myChart.setOption(option);
		}
	</script>
</html>