zoukankan      html  css  js  c++  java
  • 全球疫情统计可视化地图

    YqServlet.java

    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("echarts.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);
        }
    }

    Info.java

    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;
        }
        
    }

    Get.java

    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 info3 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;
        }
    }

    DBUtil.java

    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/yiqing1?useSSL=false&characterEncoding=UTF-8&serverTimezone=GMT";
        public static String db_user = "root";
        public static String db_pass = "123456";
        
        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();
                }
            }
        }
    
    }

    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>
    
    </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"  name="date1">
                    </div>
                    <div class="col-xs-4">
                        <h4>末时间:</h4>
                        <input type="text"  name="date2">
                    </div>
                    <div class="col-xs-2">
                        <input type="submit" value="查询">
                    </div>
                </div>
            </form>
    
        </div>
    </body>
    </html>

    echarts.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:true,
        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)
        var yd = new Array(0)
        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:"#ec4869" }
                                            //横坐标上的文字换行显示 文字颜色end
                                                 },
                data: xd
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '确诊人数',
                    type: 'bar',
                    stack: '总量',
                    data: yd,
                    barWidth:20,
                    barGap:'10%'
                }
            ]
        };
    
            myChart.setOption(option);
    }
    </script>
    
    
    <script type="text/javascript">
    var dt;
    function getAllConfirmed(){
        
        var date1 = "${date1}";
        var date2 = "${date2}";
    $.ajax({
        url:"YqServlet?method=getAllConfirmed",
        async:true,
        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)
        var yd = new Array(0)
        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:"#ec4869" }
                                            //横坐标上的文字换行显示 文字颜色end
                                                 },
                data: xd
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '确诊人数',
                    type: 'bar',
                    stack: '总量',
                    data: yd,
                    lineWidth:20,
                    lineGap:'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="900px; height: 600px;">
            
        </div>
        <table class="table" 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>

    运行截图:

     

  • 相关阅读:
    反反爬 | 如何巧过 CloudFlare 5秒盾?
    Xpath高级用法
    GZIP 头解析
    学习S5
    Chrome 建立SOCKS5代理
    建立IP6隧道
    linux 配置Socks51
    linux 配置Socks5
    最近买了一个域名 哈哈,棒棒哒~~
    jquery 动态添加下拉框 需要增加 煊染 selectmenu("refresh");
  • 原文地址:https://www.cnblogs.com/fengjingfei/p/13061631.html
Copyright © 2011-2022 走看看