Echarts学习------柱形图

 

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div id="bar" style="width: 1000px;height: 500px;">
			
		</div>
		
		<script src="../js/echarts.min.js"></script>
		<script type="text/javascript">
			var mycharts = echarts.init(document.getElementById('bar'));
			option = {
				title:{
					show : "true",   //是否显示标题
					text:"标题内容title",   //主标题的内容
					textStyle:{ 			//主标题字体样式
						color:"red",		//字体颜色
						fontStyle:"italic"	,	//字体样式  'normal' 'italic' 'oblique'
						fontWeight:	"bold",			//主标题文字字体的粗细。'normal''bold''bolder''lighter'数值
						//fontFamily:					//主标题文字的字体系列
						fontSize:30						//主标题文字的字体大小。
					},
					subtext:"子标题内容sub",
					subtextStyle:{
						//与主标题样式设置一致
					},
					left:"center",						//title 组件离容器左侧的距离。'left', 'center', 'right' 数值px
					//right:"",							//title 组件离容器右侧的距离。
					top:"top",								//title 组件离容器上侧的距离。
					//bottom:								//title 组件离容器下侧的距离。
					backgroundColor:"black",				//title组件背景颜色
					borderColor:"blue",							//title组件边框颜色
					borderWidth:5,							//title组件边框宽度
					borderRadius:10							//	title组件边框圆角
				},
				legend:{        //图例配置
					show:true,
					//left:""
					right:200,
					top:"top",
					//bottom:
					orient:"horizontal",					//图例列表的布局朝向  horizontal 水平,vertical:垂直
					data:[{
							name: '数量',
								// 强制设置图形为圆。
							icon: 'circle',
							// 设置文本为红色
							textStyle: {
								color: 'red'
							}
					}]							//	图例名称
				},
				grid:{      //网格大小配置
					
					//网格大小配置
					left:'10%',
					right:100,
					top:'20%',
					bottom:100,		
				},
				tooltip:{    //提示框
					show:true,
					trigger:"axis",   //触发方式  item  ,axis坐标轴
					backgroundColor:"#000000", //提示框背景颜色
					textStyle:{ 		//提示字体样式配置
						//配置类似主标题字体配置
						
					}
					
				},
				toolbox:{    //工具箱设置
					show:true,
					orient:"horizontal",    //工具箱显示方向  垂直或者水平	
					itemSize:15,			//工具箱图标icon大小
					itemGap:10,			//	icon间隔大小
					showTitle:true,			//显示icon标题
					feature:{				//工具箱所含功能设置
						saveAsImage:{		//保存为图片
							show:true
						},
						restore:{			//配置项还原
							show:true
						},
						dataView:{			//数据视图
							show:true,
							 readOnly:true,  //只读
						},
						 magicType:{ 			//动态类型切换
							
						},
						 dataZoom:{			//数据区域缩放
							 
						 }
					}
				},
			    xAxis: {
			        type: 'category',
			        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
			    },
			    yAxis: {     //所有配置同样适用于xAxis
					show:true,
			        type: 'value',
					axisLine:{
						show:true,  //是否显示坐标轴
						
						
							
						lineStyle:{   //坐标轴线条设置
						}
					},
					axisTick:{  //坐标轴刻度设置
						show:true
					}
			    },
			    series: [{
					name:"数量",
			        data: [120, 200, 150, 80, 70, 110, 130],
			        type: 'bar'
			    }]
			};
			mycharts.setOption(option);
		</script>
	</body>
</html>

ECharts 是一个基于 JavaScript 的开源可视化库,支持多种类型的图表,包括 3D 柱形图。而 Liquidfill 则是 ECharts 中的一个插件,可以用来创建水球图,即圆形的图表,同时支持动画效果。 要创建一个 3D 柱形图,需要在 ECharts 中引入 echarts-gl(ECharts 的 WebGL 渲染扩展库)和 echarts-liquidfill 插件。代码示例: ```js // 引入所需的模块 import * as echarts from 'echarts'; import 'echarts-gl'; import 'echarts-liquidfill'; // 初始化 ECharts 实例 const chart = echarts.init(document.getElementById('chart')); // 定义数据 const data = [ { name: 'A', value: [0, 0, 5] }, { name: 'B', value: [1, 0, 6] }, { name: 'C', value: [2, 0, 8] }, { name: 'D', value: [0, 1, 7] }, { name: 'E', value: [1, 1, 2] }, { name: 'F', value: [2, 1, 9] }, { name: 'G', value: [0, 2, 3] }, { name: 'H', value: [1, 2, 1] }, { name: 'I', value: [2, 2, 4] }, ]; // 定义配置项 const option = { grid3D: {}, xAxis3D: { type: 'category', data: ['X', 'Y', 'Z'], }, yAxis3D: { type: 'category', data: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'], }, zAxis3D: {}, series: [{ type: 'bar3D', data: data.map(item => ({ value: item.value.concat(item.value[2]), itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#00aaff', }, { offset: 1, color: '#00ffaa', }]), }, })), shading: 'color', barSize: 1, opacity: 0.8, }, { type: 'liquidFill', data: data.map(item => ({ value: item.value[2] / 10, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#00aaff', }, { offset: 1, color: '#00ffaa', }]), }, })), shape: 'circle', label: { show: true, fontSize: 16, color: '#fff', formatter: '{b}', }, }], }; // 使用配置项生成图表 chart.setOption(option); ``` 上述代码中,`data` 数组定义了每个柱形图的名称和坐标位置,`option` 对象则定义了图表的配置项。其中,`grid3D`、`xAxis3D`、`yAxis3D` 和 `zAxis3D` 用于定义 3D 坐标系,`series` 则用于定义 3D 柱形图和水球图。柱形图的样式可以通过 `itemStyle` 属性进行设置,而水球图则可以通过 `liquidFill` 类型的系列来创建。 最后,使用 `setOption` 方法将配置项传入,即可在页面中生成 3D 柱形图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值