• 大二下学期第一次结对作业(第一阶段)


    今日完成了根据日期查询不同时间的各省的确诊人数:

    首先是三个输入框分别输入年,月,日然后用按钮绑定一个点击事件,获取年月日传给后台,

    最后后台将数据库查询的结果返回,在渲染图表。主要代码:

    var btn = document.getElementById("query");
            btn.onclick = function(){
                var year=document.getElementById("queryyear").value;
                var day=document.getElementById("queryday").value;
                var month=document.getElementById("querymonth").value;
                $.ajax({
                    url:"/query",
                    data: {year: year,day:day,month:month },
                    success: function (data) {
                        bar1_option.xAxis[0].data=data.name;
                        bar1_option.series[0].data=data.value;
                        bar1_myChart.setOption(bar1_option);
                    },
                    error: function (xhr, type, errorThrown) {
                    }
                })
            }
    @app.route('/query')
    def get_query_data():
        year=request.values.get("year")
        print(year)
        month=request.values.get("month")
        print(month)
        day=request.values.get("day")
        print(day)
        name=[]
        value=[]
        for tup ,v in utils.get_query_data(year,month,day):
            name.append(tup)
            value.append(v)
        return jsonify({"name":name,"value":value})
    def get_query_data(year,month,day):
        Year=str(year)
        Month=str(month)
        Day=str(day)
        ds = Year+"." + Month+"."+Day
        print(ds)
        tup = time.strptime(ds, "%Y.%m.%d")
        print(tup)
        ds = time.strftime("%Y-%m-%d", tup)
        Year=str(year)
        Month=str(month)
        Day=str(int(day)+1)
        ds1 = Year+"." + Month+"."+Day
        print(ds1)
        tup1 = time.strptime(ds1, "%Y.%m.%d")
        print(tup1)
        ds1 = time.strftime("%Y-%m-%d", tup1)
        print(ds1)
        sql = 'select province,sum(confirm) from details '
              'where update_time between '+"'"+ds+"'"+' and '+"'"+ds1+"'"+' group by province'
        res = query(sql)
        print(res)
        return res

    效果图:

    这样第一次结对作业,大部分已经完成,只差地图下钻,虽然根据网上的资源可以实现下钻,但是自己并不会赋值,

    原因就是自己第一次接触python对于找到的代码的语法以及结构不清楚。明日将继续研究地图下钻。

    下面为可视化的整体效果:

  • 相关阅读:
    一个好用的H5tab切换(抽屉功能)
    jQuery的ajax请求
    原生js的ajax请求
    微信小程序封装get、post请求
    微信小程序 data数据的赋值和取值
    gitLab更新文件命令
    vue中localStorage的使用
    linux就该这么学--课程第15天
    linux就该这么学--课程第14天
    linux就该这么学--课程第13天
  • 原文地址:https://www.cnblogs.com/fengchuiguobanxia/p/14545895.html
Copyright © 2020-2023  润新知