全国疫情统计可视化地图(第一阶段)

Posted xhj1074376195

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了全国疫情统计可视化地图(第一阶段)相关的知识,希望对你有一定的参考价值。

技术图片

 

 

 

DBUtil.java

package com.helloechart;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBUtil {
    
    public static String db_url = "jdbc:mysql://localhost:3306/test?useSSL=false&characterEncoding=UTF-8&serverTimezone=GMT";
    public static String db_user = "root";
    public static String db_pass = "root";
    
    public static Connection getConn () {
        Connection conn = null;
        
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(db_url, db_user, db_pass);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return conn;
    }

    public static void close (Statement state, Connection conn) {
        if (state != null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    
    public static void close (ResultSet rs, Statement state, Connection conn) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        
        if (state != null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}

 

Get.java

package com.helloechart;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class Get {
    public List<Info> listAll(String date1,String date2) {
        ArrayList<Info> list = new ArrayList<>();
        Connection conn=DBUtil.getConn();
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        String sql="select * from info where Date between ? and ?";
        try {
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, date1);
            pstmt.setString(2, date2);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                Info yq = new Info();
                yq.setId(rs.getInt(1));
                yq.setDate(rs.getString(2));
                yq.setProvince(rs.getString(3));
                yq.setCity(rs.getString(4));
                yq.setConfirmed_num(rs.getString(5));
                yq.setYisi_num(rs.getString(6));
                yq.setCured_num(rs.getString(7));
                yq.setDead_num(rs.getString(8));
                yq.setCode(rs.getString(9));
                list.add(yq);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                conn.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return list;
    }
}

 

Info.java

package com.helloechart;

public class Info {
    private int id;
    private String city;
    private String yisi_num;
    private String date;
    private String province;
    private String confirmed_num;
    private String cured_num;
    private String dead_num;
    private String code;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getYisi_num() {
        return yisi_num;
    }
    public void setYisi_num(String yisi_num) {
        this.yisi_num = yisi_num;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public String getProvince() {
        return province;
    }
    public void setProvince(String province) {
        this.province = province;
    }
    public String getConfirmed_num() {
        return confirmed_num;
    }
    public void setConfirmed_num(String confirmed_num) {
        this.confirmed_num = confirmed_num;
    }
    public String getCured_num() {
        return cured_num;
    }
    public void setCured_num(String cured_num) {
        this.cured_num = cured_num;
    }
    public String getDead_num() {
        return dead_num;
    }
    public void setDead_num(String dead_num) {
        this.dead_num = dead_num;
    }
    
}

 

YqServlet.java

package com.helloechart;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.gson.Gson;


/**
 * Servlet implementation class SearchConfirmedServlet
 */
@WebServlet("/YqServlet")
public class YqServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    Get get=new Get();
    /**
     * @see HttpServlet#HttpServlet()
     */
    public YqServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method");
        if(method.equals("getAllProvince")) {
            getAllProvince(request, response);
        }else if(method.equals("getAllConfirmed")) {
            getAllConfirmed(request, response);
        }
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
    protected void getAllProvince(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        String date1 = request.getParameter("date1");
        String date2 = request.getParameter("date2");
        List<Info> list = get.listAll(date1,date2);
        request.setAttribute("list",list);
        request.setAttribute("date1",date1);
        request.setAttribute("date2",date2);
        request.getRequestDispatcher("bar.jsp").forward(request, response);
    }
    
    protected void getAllConfirmed(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        String date1 = request.getParameter("date1");
        String date2 = request.getParameter("date2");
        System.out.println(date1);
        System.out.println(date2);
        List<Info> list = get.listAll(date1,date2);
        HttpSession session = request.getSession();
        session.setAttribute("list",list);
        Gson gson = new Gson();
        String json = gson.toJson(list);
        response.getWriter().write(json);
    }
}

 

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Insert title here</title>
<link href="${pageContext.request.contextPath }/bootstrap-3.3.7-dist/css/bootstrap.min.css"  rel="stylesheet">
<script src="${pageContext.request.contextPath }/js/jquery-3.3.1.min.js"></script>
<script src="${pageContext.request.contextPath }/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

<style type="text/css">
    .skyblue{
        background:skyblue;
    }
    .pink{
        background:pink;
    }
    *{
        margin:0px;
        padding:0px;
    }
    a{
        font-size:15px;
    }
    
</style>
</head>
<body>
    <div class="container">
        <form action="YqServlet?method=getAllProvince" method="post">
            <div class="row" style="padding-top: 20px">
                <div class="col-xs-4">
                    <h4>起始时间:</h4>
                    <input type="text" class="form-control" name="date1">
                </div>
                <div class="col-xs-4">
                    <h4>终止时间:</h4>
                    <input type="text" class="form-control" name="date2">
                </div>
                <div class="col-xs-2">
                    <input type="submit" class="btn btn-default" value="查询">
                </div>
            </div>
        </form>

    </div>
</body>
</html>

 

bar.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link href="${pageContext.request.contextPath }/bootstrap-3.3.7-dist/css/bootstrap.min.css"  rel="stylesheet">
<script src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath }/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/echarts.min.js"></script>
</head>
<script type="text/javascript">
var dt;
function getAllConfirmed(){
    
    var date1 = "${date1}";
    var date2 = "${date2}";
$.ajax({
    url:"YqServlet?method=getAllConfirmed",
    async:false,
    type:"POST",
    data:{"date1":date1,
          "date2":date2
         },
    success:function(data){
        dt = data;
        //alert(dt);
    },
    error:function(){
        alert("请求失败");
    },
    dataType:"json"
});
    
    var myChart = echarts.init(document.getElementById(yiqingchart));
    var xd = new Array(0)//长度为33
    var yd = new Array(0)//长度为33
    for(var i=0;i<32;i++){
        xd.push(dt[i].province);
        yd.push(dt[i].confirmed_num);
    }
        // 指定图表的配置项和数据
       var option = {
        title: {
            text: 全国各省的确诊人数
        },
        tooltip: {
            show: true,
            trigger: axis
            
        },
        legend: {
            data: [确诊人数]
        },
        grid: {
            left: 3%,
            right: 4%,
            bottom: 3%,
            containLabel: true
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        xAxis: {
            type: category,
            boundaryGap: false,
            axisLabel:{
                                        //横坐标上的文字斜着显示 文字颜色 begin 
                                             interval:0,
                                             rotate:45,
                                             margin:60,
                                             textStyle:{color:"#ec6869" }
                                        //横坐标上的文字换行显示 文字颜色end
                                             },
            data: xd
        },
        yAxis: {
            type: value
        },
        series: [
            {
                name: 确诊人数,
                type: bar,
                stack: 总量,
                data: yd,
                barWidth:20,
                barGap:10%
            }
        ]
    };

       

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
}
</script>
<body>
    <button class="btn btn-default" onclick="getAllConfirmed()" style="padding-top:20px;font-size:20px">柱状图</button>
    <div id="yiqingchart" style="width:900px; height: 600px;">
        
    </div>
    <table class="table table-striped" style="font-size:20px">
        <tr>
            <td>编号</td>
            <td>日期</td>
            <td>省份</td>
            <td>城市</td>
            <td>确诊人数</td>
            <td>疑似人数</td>
            <td>治愈人数</td>
            <td>死亡人数</td>
        </tr>
        <c:forEach items="${list}" var="info">
        <tr>
            <td>${info.id}</td>
            <td>${info.date}</td>
            <td>${info.province}</td>
            <td>${info.city}</td>
            <td>${info.confirmed_num}</td>
            <td>${info.yisi_num}</td>
            <td>${info.cured_num}</td>
            <td>${info.dead_num}</td>
        </tr>
        </c:forEach>
    </table>
</body>
</html>

 

以上是关于全国疫情统计可视化地图(第一阶段)的主要内容,如果未能解决你的问题,请参考以下文章

全国疫情统计可视化地图

全国疫情统计可视化地图

全国疫情统计可视化地图

全国疫情统计地图可视化

基于json数据对全国疫情数据可视化

全国疫情防控监控平台开发