echarts4 统计图表几种样板

先看效果图!

 

直接上代码!

 
<!DOCTYPE html">
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=Edge">
 

 <script type="text/javascript" src=" F:\hlzs\sfpt\HolyCore\WebRoot\js\jquery-1.11.3.min.js"></script>
	<script type="text/javascript" src="E:\Download\incubator-echarts-4.5.0\dist\echarts.min.js"></script>
	<style>
#root {
	width: 900px;
}

#navigation {
	height: 41px;;
	width: 60%
}

#navigation div {
	float: left;
	margin-right: 10px;
	background-color: BBBBBB;
	height: 40px;
	width: 100px;
	line-height: 40px;
	font-size: 16px;
	text-align: center;
	border: 1px solid;
	border-radius: 5px 5px 0 0;
	font-weight: 400;
	border-bottom: #FFFFFF;
}

#content {
	width: 60%;
	height: 350px;
}

#content div {
	width: 950px;
	height: 350px;
	background-color: #FFFFFF;
	/* display:none;		 */
}
</style>
</head>
<body>
	<div id="root">
		<div id="navigation">
			<div id="sstb">收税同比</div>
			<div id="sszb">税收占比</div>
			<div id="sffx">税负分析</div>
			<div id="wnqs">五年趋势</div>
		</div>
		<div id="content">
			<div id="c_sstb">1</div>
			<div id="c_sszb">2</div>
			<div id="c_sffx">3</div>
			<div id="c_wnqs">4</div>
		</div>
	</div>
</body>
<script>
	/* var msgObj = ${msg};
	holycore.message(msgObj); */

	$(function() {
		var pre = "c_sstb";
		var c = "#c_sstb";
		$("#navigation>div").each(function() {
			chart(this.id);
			$(this).bind("click", function() {
				debugger;
				if (pre == null) {
					$(this).css("background", "#FFFFFF");
					pre = "#" + this.id;
					c = "#" + "c_" + this.id;
					$(c).toggle();
				} else if (pre != ('#' + this.id)) {
					$(this).css("background", "#FFFFFF");
					$(c).toggle();
					c = "#" + "c_" + this.id;
					$(c).toggle();
					$(pre).css("background", "#BBBBBB");
					pre = "#" + this.id;
				}
			});
		});

	});
	/* 	$("#navigation>div").each(function(){
	 chart("#c_"+this.id);
	 }); */
	//chart("c_sstb");
	function chart(id) {
		id = "c_" + id;
		if (id == "c_sstb") {
			chart1(id);
		} else if (id == "c_sszb") {
			chart3(id);
		} else if (id == "c_sffx") {
			chart2(id);
		} else if (id == "c_wnqs") {
			chart4(id);
		}
		if (id != "c_sstb") {
			$("#" + id).toggle();
		}
	}
	function chart1(id) {
		// 基于准备好的dom,初始化echarts实例
		var myChart = echarts.init(document.getElementById(id));
		// 指定图表的配置项和数据
		var option = {
			title : {
				text : 'ECharts 入门示例'
			},
			tooltip : {},
			legend : {
				data : [ '销量' ]
			},
			xAxis : {
				data : [ "衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子" ]
			},
			yAxis : {},
			series : [ {
				name : '销量',
				type : 'bar',
				data : [ 5, 20, 36, 10, 10, 20 ]
			} ]
		};

		// 使用刚指定的配置项和数据显示图表。
		myChart.setOption(option);
	}

	function chart2(id) {
		// 基于准备好的dom,初始化echarts实例
		var myChart = echarts.init(document.getElementById(id));
		option = {
			/* legend : {
				data : [ '2018', '2019' ]
			}, */
			tooltip : {
				trigger : 'axis',
				extraCssText : 'width:150px;height:300px;',
				position : function(point, params, dom) {
					var posDis = window.innerWidth - dom.offsetWidth;
					return posDis < point[0] ? [ posDis, '10%' ] : [ point[0],
							'10%' ];
				},
				formatter: '{b}<br />{a0}: {c0}<br />{a1}: {c1}'
			},
			grid : {
				left : '3%',
				right : '4%',
				bottom : '3%',
				top : '8%',
				containLabel : true
			},
			xAxis : [ {
				type : 'category',
				data : [ '贵阳市', '遵义市', '六盘水市', '毕节市' ]
			} ],
			yAxis : [ {
				type : 'value'
			} ],
			series : [ {
				name : '2018年',
				type : 'bar',
				barGap : '0',//柱图间距
				data : [ 320, 332, 301, 334 ],
				itemStyle : {
					normal : {
						color:'#1E90FF',
						label : {
							show : false,
							position : 'top',
							formatter : "{a}: {c}",
							textStyle : {
								color : 'blue'
							}
						}
					}
				}
			}, {
				name : '2019年',
				type : 'bar',
				stack : '广告',
				barGap : '0',//柱图间距
				data : [ 120, 132, 101, 134 ],
				itemStyle : {
					normal : {
						color: '#00FF00',
						label : {
							show : false,
							position : 'top',
							formatter : "{a}: {c}",
							textStyle : {
								color : 'blue'
							}
						}
					}
				}
			} ]
		};

		// 使用刚指定的配置项和数据显示图表。
		myChart.setOption(option);
	}

	function chart3(id) {
		// 基于准备好的dom,初始化echarts实例
		var myChart = echarts.init(document.getElementById(id));
		option = {
				tooltip : {
					trigger : 'item',
					extraCssText : 'width:150px;height:300px;',
					position : function(point, params, dom) {
						var posDis = window.innerWidth - dom.offsetWidth;
						return posDis < point[0] ? [ posDis, '10%' ] : [ point[0],
								'10%' ];
					}
				},
			legend : {
				bottom : 0,
				x : 'center',
				data : [ '直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎' ]
			},
			grid : {
				left : '3%',
				right : '4%',
				bottom : '3%',
				top : '8%',
				containLabel : true
			},
			series : [ {
				name : '访问来源',
				type : 'pie',
				radius : [ '50%', '70%' ],
				avoidLabelOverlap : false,
				label : {
					normal : {
						show : true,
						formatter : '{b}: {d}%'
					}
				},
				data : [ {
					value : 335,
					name : '直接访问'
				}, {
					value : 310,
					name : '邮件营销'
				}, {
					value : 234,
					name : '联盟广告'
				}, {
					value : 135,
					name : '视频广告'
				}, {
					value : 1548,
					name : '搜索引擎'
				} ]
			} ]
		};
		myChart.setOption(option);
	}

	function chart4(id) {
		// 基于准备好的dom,初始化echarts实例
		var myChart = echarts.init(document.getElementById(id));
		option = {
			/* 			title : {
			 text : '折线图堆叠'
			 },
			 */tooltip : {
				trigger : 'axis',
				extraCssText : 'width:150px;height:300px;',
				position : function(point, params, dom) {
					var posDis = window.innerWidth - dom.offsetWidth;
					return posDis < point[0] ? [ posDis, '10%' ] : [ point[0],
							'10%' ];
				}
			},
			legend : {
				data : [ '邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎' ]
			},
			grid : {
				left : '3%',
				right : '4%',
				bottom : '3%',
				top : '8%',
				containLabel : true
			},
			/* 		toolbox : {
						feature : {
							saveAsImage : {}
						}
					}, */
			xAxis : {
				type : 'category',
				boundaryGap : false,
				data : [ '周一', '周二', '周三', '周四', '周五', '周六', '周日' ]
			},
			yAxis : {
				type : 'value'
			},
			series : [ {
				name : '邮件营销',
				type : 'line',
				stack : '总量',
				data : [ 120, 132, 101, 134, 90, 230, 210 ]
			}, {
				name : '联盟广告',
				type : 'line',
				stack : '总量',
				data : [ 220, 182, 191, 234, 290, 330, 310 ]
			}, {
				name : '视频广告',
				type : 'line',
				stack : '总量',
				data : [ 150, 232, 201, 154, 190, 330, 410 ]
			}, {
				name : '直接访问',
				type : 'line',
				stack : '总量',
				data : [ 320, 332, 301, 334, 390, 330, 320 ]
			}, {
				name : '搜索引擎',
				type : 'line',
				stack : '总量',
				data : [ 820, 932, 901, 934, 1290, 1330, 1320 ]
			} ]
		};
		myChart.setOption(option);
	}
</script>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值