欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

echarts地图入门

程序员文章站 2022-03-04 13:49:27
...

taglibs.jsp文件  :设置系统路径,及引入el表达式

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+":"+"//"+request.getServerName()+":"+request.getServerPort()+path;
if(request.getServerPort()==80){
	basePath = request.getScheme()+":"+"//"+request.getServerName()+path;
}

%>
<c:set var="basePath" value="<%=basePath %>"/>

jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


<%@include file= "/jsp/common/taglibs.jsp" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>中国地图</title>
<script
  src="https://code.jquery.com/jquery-3.3.1.js"
    integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
  crossorigin="anonymous"></script>
  
<script type="text/javascript" src="${basePath}/js/echarts/echarts.js"></script>
</head>
<body>




	<!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
    <div id="map" style="width: 800px;height:600px;"></div>


	<script type="text/javascript">
		var basePath = '<%=basePath%>';  
		$.getJSON(basePath+'/js/echarts/china.json', function (data) {
		    echarts.registerMap('china', data);
		    var chart = echarts.init(document.getElementById('map'));
		    chart.setOption({
		        series: {
		            type: 'map',
		            map: 'china',
		            data:[
                                    {name:'四川', selected:true}//福建为选中状态
                                ]
		        }
		    });
		});
	</script>


</body>
</html>

完整war包下载地址

完整war包代码