• Flask+Echarts搭建全国疫情可视化大屏


    目录

    需求分析

    项目实施

    1.数据采集 

    2.搭建flask应用 

    3.可视化展示 

    第一板块

    第二板块

    第三板块

    第四板块

    4.添加定时任务

    项目总结


    本项目是基于flask+echarts搭建的全国疫情实时追踪的可视化大屏,主要涉及到的技术有爬虫,mysql数据库,flask框架,echarts图表。关于flask知识点,可学习另一篇文章Flask全套知识点从入门到精通,学完可直接做项目

    最终效果如下:

    需求分析

    从最终效果图可以看出,我们将屏幕分为4大板块(页面排布是左中右+上),第一板块是最上面的部分,包括大屏标题以及当前的实时时间;第二板块是最左边,上面的全国新增趋势折线图(新增确诊、治愈、死亡),下面是全国累计趋势折线图(累计确诊、治愈、死亡);第三板块是中间,上面是当天的一些数据,下面是全国累计确诊的疫情地图;第四板块是右边,上面是新增确诊人数Top前五的省份柱状图,下面是微博热搜话题的词云图。

    开发工具:

    vscode编辑器

    python3.8

    如果你在开发的过程中发现你编写的html或css文件在页面中没有更新,而是你上次编写的代码,也就是缓存的问题,这时候你需要在app.py中添加如下代码即可解决:

    1. @app.after_request
    2. def apply_caching(response):
    3. response.headers["Cache-Control"] = "no-cache"
    4. return response

    项目实施

    项目的最终文件目录结构如下:

    1.数据采集 

    首先,我们得要有数据才能进行展示,这里我们选择用爬虫来进行数据采集并保存到mysql数据库中,考虑到平台限制,这里就不方便展示爬虫代码,需要的评论留言或私信。

    2.搭建flask应用 

    这里我们先搭建一个基础的flask应用

    1. from flask import Flask,render_template
    2. app = Flask(__name__)
    3. app.config['JSON_AS_ASCII'] = False
    4. @app.route('/')
    5. def index():
    6. return render_template('main.html')
    7. if __name__ == '__main__':
    8. app.run(debug=True)

    接着,需要编写main.html页面(这里我就直接放最终的代码)

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <title>全国疫情实时追踪title>
    8. <link rel="stylesheet" href="../static/css/main.css">
    9. <script src="../static/js/echarts.min.js">script>
    10. <script src="../static/js/china.js">script>
    11. <script src="../static/js/jquery-3.6.0.min.js">script>
    12. <script src="../static/js/echarts-wordcloud.min.js">script>
    13. head>
    14. <body>
    15. <div class="title">全国疫情实时追踪div>
    16. <div class="tim">div>
    17. <div class="l1" id="l1">div>
    18. <div class="l2" id="l2">div>
    19. <div class="c1">
    20. <div class="num"><h1>h1>div>
    21. <div class="num"><h1>h1>div>
    22. <div class="num"><h1>h1>div>
    23. <div class="num"><h1>h1>div>
    24. <div class="txt"><h2>累计确诊h2>div>
    25. <div class="txt"><h2>新增确诊h2>div>
    26. <div class="txt"><h2>累计治愈h2>div>
    27. <div class="txt"><h2>累计死亡h2>div>
    28. div>
    29. <div class="c2" id="main" >div>
    30. <div class="r1" id="r1">div>
    31. <div class="r2" id="r2">div>
    32. <script src="../static/js/get_data.js">script>
    33. <script src="../static/js/ec_center.js">script>
    34. <script src="../static/js/ec_left1.js">script>
    35. <script src="../static/js/ec_left2.js">script>
    36. <script src="../static/js/ec_right1.js">script>
    37. <script src="../static/js/ec_right2.js">script>
    38. body>
    39. html>

    其次,我们还需要编写css来进行板块划分

    main.css

    1. body{
    2. margin: 0;
    3. background-color: #333;
    4. }
    5. .title{
    6. position: absolute;
    7. width: 40%;
    8. height: 10%;
    9. top: 0;
    10. left: 30%;
    11. color: white;
    12. font-size: 40px;
    13. display: flex;
    14. align-items: center;
    15. justify-content: center;
    16. }
    17. .l1{
    18. position: absolute;
    19. width: 30%;
    20. height: 45%;
    21. top: 10%;
    22. left: 0;
    23. background-color: aquamarine;
    24. }
    25. .l2{
    26. position: absolute;
    27. width: 30%;
    28. height: 45%;
    29. top: 55%;
    30. left: 0;
    31. background-color: blue;
    32. }
    33. .c1{
    34. position: absolute;
    35. width: 40%;
    36. height: 25%;
    37. top: 10%;
    38. left: 30%;
    39. /* background-color: blue; */
    40. }
    41. .num{
    42. width: 25%;
    43. float: left;
    44. display: flex;
    45. align-items: center;
    46. justify-content: center;
    47. color: gold;
    48. font-size: 16px;
    49. }
    50. .txt{
    51. width: 25%;
    52. float: left;
    53. display: flex;
    54. align-items: center;
    55. justify-content: center;
    56. font-family: "幼圆";
    57. color: whitesmoke;
    58. font-size: 14px;
    59. }
    60. .c2{
    61. position: absolute;
    62. width: 40%;
    63. height: 65%;
    64. top: 35%;
    65. left: 30%;
    66. /* background-color: whitesmoke; */
    67. }
    68. .r1{
    69. position: absolute;
    70. width: 30%;
    71. height: 45%;
    72. top: 10%;
    73. right: 0;
    74. background-color: burlywood;
    75. }
    76. .r2{
    77. position: absolute;
    78. width: 30%;
    79. height: 45%;
    80. top: 55%;
    81. right: 0;
    82. background-color: brown;
    83. }
    84. .tim{
    85. position: absolute;
    86. /* width: 30%; */
    87. height: 10%;
    88. top: 5%;
    89. right: 2%;
    90. /* background-color: blueviolet; */
    91. font-size: 20px;
    92. color: whitesmoke;
    93. }

    3.可视化展示 

    接下来我将按照4大板块进行介绍

    第一板块

    那个大屏标题文字在上面的html页面中有,这里就不说了。还有一个就是右上角的时间显示,这里我们需要编写一个获取时间的接口,然后通过ajax来发送请求进行调用.

    utils.py

    1. import time
    2. import pymysql
    3. import collections
    4. import jieba
    5. import re
    6. def get_time():
    7. time_str = time.strftime('%Y{}%m{}%d{} %X ')
    8. return time_str.format('年','月','日')

    app.py

    1. import utils
    2. @app.route('/time')
    3. def time():
    4. return utils.get_time()

    get_data.js

    1. function gettime(){
    2. $.ajax({
    3. url:'/time',
    4. timeout:10000,//超时时间
    5. success:function(data){
    6. $('.tim').html(data)
    7. },
    8. error:function(data){
    9. }
    10. });
    11. };
    '
    运行

    第二板块

    第二板块是左边的两个图

    流程步骤就是先从数据库中获取数据,在flask应用中编写接口,最后在页面中通过ajax来发送进行调用,这是图表展示的通用步骤,下面我就不再叙述了。

    这里因为我们要多次从数据库获取数据,所以 我们先封装一下方法,便于后面获取数据

    utils.py

    1. def get_conn():
    2. """
    3. :return: 连接,游标
    4. """
    5. # 创建连接
    6. conn = pymysql.connect(host="127.0.0.1",
    7. user="xxx", # 这里写你的mysql用户名
    8. password="xxx", # 这里写你的mysql密码
    9. db="yiqing", # 这里写你的mysql中创建的数据库
    10. charset="utf8")
    11. # 创建游标
    12. cursor = conn.cursor()# 执行完毕返回的结果集默认以元组显示
    13. return conn, cursor
    14. def close_conn(conn, cursor):
    15. cursor.close()
    16. conn.close()
    17. def query(sql,*args):
    18. """
    19. 封装通用查询
    20. :param sql:
    21. :param args:
    22. :return: 返回查询到的结果,((),(),)的形式
    23. """
    24. conn, cursor = get_conn()
    25. cursor.execute(sql,args)
    26. res = cursor.fetchall()
    27. close_conn(conn, cursor)
    28. return res

    左上的图:

    utils.py

    1. def get_l1_data():
    2. # 因为会更新多次数据,取时间戳最新的那组数据
    3. sql = '''
    4. SELECT ds,confirm_add,heal_add,dead_add
    5. FROM history
    6. '''
    7. res = query(sql)
    8. return res

    app.py

    1. from flask import jsonify
    2. @app.route('/l1')
    3. def get_l1_data():
    4. data = utils.get_l1_data()
    5. day,confirm_add,heal_add,dead_add = [],[],[],[]
    6. for item in data:
    7. day.append(item[0].strftime('%m-%d'))
    8. confirm_add.append(item[1])
    9. heal_add.append(item[2])
    10. dead_add.append(item[3])
    11. return jsonify({'day':day,'confirm_add':confirm_add,'heal_add':heal_add,'dead_add':dead_add})

    get_data.js

    1. function get_l1_data(){
    2. $.ajax({
    3. url:'/l1',
    4. success:function(data){
    5. ec_left1_Option.xAxis[0].data=data.day
    6. ec_left1_Option.series[0].data=data.confirm_add
    7. ec_left1_Option.series[1].data=data.heal_add
    8. ec_left1_Option.series[2].data=data.dead_add
    9. ec_left1.setOption(ec_left1_Option)
    10. },
    11. error:function(data){
    12. }
    13. });
    14. }
    '
    运行

    ec_left1.js

    1. var ec_left1 = echarts.init(document.getElementById('l1'), "dark");
    2. var ec_left1_Option = {
    3. tooltip: {
    4. trigger: 'axis',
    5. //指示器
    6. axisPointer: {
    7. type: 'line',
    8. lineStyle: {
    9. color: '#7171C6'
    10. }
    11. },
    12. },
    13. legend: {
    14. data: ['新增确诊', '新增治愈','新增死亡'],
    15. left: "right"
    16. },
    17. //标题样式
    18. title: {
    19. text: "全国新增趋势",
    20. textStyle: {
    21. color: 'white',
    22. },
    23. left: 'left'
    24. },
    25. //图形位置
    26. grid: {
    27. left: '4%',
    28. right: '6%',
    29. bottom: '4%',
    30. top: 50,
    31. containLabel: true
    32. },
    33. xAxis: [{
    34. type: 'category',
    35. data: []
    36. }],
    37. yAxis: [{
    38. type: 'value',
    39. //y轴线设置显示
    40. axisLine: {
    41. show: true
    42. },
    43. position:'left',
    44. axisLabel: {
    45. show: true,
    46. color: 'white',
    47. fontSize: 12,
    48. formatter: function(value) {
    49. if (value >= 1000) {
    50. value = value / 1000 + 'k';
    51. }
    52. return value;
    53. }
    54. },
    55. //与x轴平行的线样式
    56. splitLine: {
    57. show: true,
    58. lineStyle: {
    59. width: 1,
    60. }
    61. }
    62. },
    63. {
    64. type: 'value',
    65. //y轴线设置显示
    66. axisLine: {
    67. show: true
    68. },
    69. position:'right',
    70. axisLabel: {
    71. show: true,
    72. color: 'white',
    73. fontSize: 12,
    74. formatter: function(value) {
    75. return value;
    76. }
    77. },
    78. //与x轴平行的线样式
    79. splitLine: {
    80. show: true,
    81. lineStyle: {
    82. width: 1,
    83. }
    84. }
    85. }
    86. ],
    87. series: [{
    88. name: "新增确诊",
    89. type: 'line',
    90. smooth: true,
    91. yAxisIndex:0,
    92. data: []
    93. }, {
    94. name: "新增治愈",
    95. type: 'line',
    96. smooth: true,
    97. yAxisIndex:1,
    98. data: []
    99. },{
    100. name: "新增死亡",
    101. type: 'line',
    102. smooth: true,
    103. yAxisIndex:1,
    104. data: []
    105. }
    106. ]
    107. };
    108. ec_left1.setOption(ec_left1_Option)

    左下:

    utils.py

    1. def get_l2_data():
    2. sql = '''
    3. SELECT ds,confirm,heal,dead
    4. FROM history;
    5. '''
    6. res = query(sql)
    7. return res

    app.py

    1. @app.route('/l2')
    2. def get_l2_data():
    3. data = utils.get_l2_data()
    4. day,confirm,heal,dead = [],[],[],[]
    5. for item in data:
    6. day.append(item[0].strftime('%m-%d'))
    7. confirm.append(item[1])
    8. heal.append(item[2])
    9. dead.append(item[3])
    10. return jsonify({'day':day,'confirm':confirm,'heal':heal,'dead':dead})

    get_data.js

    1. function get_l2_data(){
    2. $.ajax({
    3. url:'/l2',
    4. success:function(data){
    5. ec_left2_Option.xAxis[0].data=data.day
    6. ec_left2_Option.series[0].data=data.confirm
    7. ec_left2_Option.series[1].data=data.heal
    8. ec_left2_Option.series[2].data=data.dead
    9. ec_left2.setOption(ec_left2_Option)
    10. },
    11. error:function(data){
    12. }
    13. });
    14. }
    '
    运行

    ec_left2.js

    1. var ec_left2 = echarts.init(document.getElementById('l2'), "dark");
    2. var ec_left2_Option = {
    3. tooltip: {
    4. trigger: 'axis',
    5. //指示器
    6. axisPointer: {
    7. type: 'line',
    8. lineStyle: {
    9. color: '#7171C6'
    10. }
    11. },
    12. },
    13. legend: {
    14. data: ['累计确诊', '累计治愈','累计死亡'],
    15. left: "right"
    16. },
    17. //标题样式
    18. title: {
    19. text: "全国累计趋势",
    20. textStyle: {
    21. color: 'white',
    22. },
    23. left: 'left'
    24. },
    25. //图形位置
    26. grid: {
    27. left: '4%',
    28. right: '6%',
    29. bottom: '4%',
    30. top: 50,
    31. containLabel: true
    32. },
    33. xAxis: [{
    34. type: 'category',
    35. data: []
    36. }],
    37. yAxis: [{
    38. type: 'value',
    39. //y轴字体设置
    40. //y轴线设置显示
    41. axisLine: {
    42. show: true
    43. },
    44. axisLabel: {
    45. show: true,
    46. color: 'white',
    47. fontSize: 12,
    48. formatter: function(value) {
    49. if (value >= 1000) {
    50. value = value / 1000 + 'k';
    51. }
    52. return value;
    53. }
    54. },
    55. //与x轴平行的线样式
    56. splitLine: {
    57. show: true,
    58. lineStyle: {
    59. // color: '#FFF',
    60. width: 1,
    61. // type: 'solid',
    62. }
    63. }
    64. },
    65. {
    66. type: 'value',
    67. //y轴线设置显示
    68. axisLine: {
    69. show: true
    70. },
    71. position:'right',
    72. axisLabel: {
    73. show: true,
    74. color: 'white',
    75. fontSize: 12,
    76. formatter: function(value) {
    77. if (value >= 1000) {
    78. value = value / 1000 + 'k';
    79. }
    80. return value;
    81. }
    82. },
    83. //与x轴平行的线样式
    84. splitLine: {
    85. show: true,
    86. lineStyle: {
    87. width: 1,
    88. }
    89. }
    90. } ],
    91. series: [{
    92. name: "累计确诊",
    93. type: 'line',
    94. smooth: true,
    95. yAxisIndex:0,
    96. data: []
    97. }, {
    98. name: "累计治愈",
    99. type: 'line',
    100. smooth: true,
    101. yAxisIndex:1,
    102. data: []
    103. },{
    104. name: "累计死亡",
    105. type: 'line',
    106. smooth: true,
    107. yAxisIndex:1,
    108. data: []
    109. }
    110. ]
    111. };
    112. ec_left2.setOption(ec_left2_Option)

    第三板块

    第三板块是中间部分

    先完成上面的数值数据填充

    utils.py

    1. def get_c1_data():
    2. """
    3. :return: 返回大屏div id=c1 的数据
    4. """
    5. # 因为会更新多次数据,取时间戳最新的那组数据
    6. sql = """
    7. SELECT confirm,confirm_add,heal,dead
    8. FROM history
    9. ORDER BY ds DESC LIMIT 1;
    10. """
    11. res = query(sql)
    12. return res[0]

    app.py

    1. @app.route('/c1')
    2. def get_c1_data():
    3. data = utils.get_c1_data()
    4. return jsonify({'confirm':int(data[0]),'confirm_add':int(data[1]),'heal':int(data[2]),'dead':int(data[3])})

    get_data.js

    1. function get_c1_data(){
    2. $.ajax({
    3. url:'/c1',
    4. success:function(data){
    5. $(".num h1").eq(0).text(data.confirm)
    6. $(".num h1").eq(1).text(data.confirm_add)
    7. $(".num h1").eq(2).text(data.heal)
    8. $(".num h1").eq(3).text(data.dead)
    9. },
    10. error:function(data){
    11. }
    12. });
    13. }
    '
    运行

    接着完成下面的地图

    utils.py

    1. def get_c2_data():
    2. """
    3. :return: 返回各省数据
    4. """
    5. # 因为会更新多次数据,取时间戳最新的那组数据
    6. sql = '''
    7. SELECT province,sum(confirm_now)
    8. FROM details
    9. GROUP BY province;
    10. '''
    11. res = query(sql)
    12. return res

    app.py

    1. @app.route('/c2')
    2. def get_c2_data():
    3. res = []
    4. for item in utils.get_c2_data():
    5. res.append({'name':item[0],'value':int(item[1])})
    6. return jsonify({'data':res})

    get_data.py

    1. function get_c2_data(){
    2. $.ajax({
    3. url:'/c2',
    4. success:function(data){
    5. ec_center_option.series[0].data=data.data
    6. ec_center_option.series[0].data.push({
    7. name:"南海诸岛",value:0
    8. })
    9. ec_center.setOption(ec_center_option)
    10. },
    11. error:function(data){
    12. }
    13. });
    14. }
    '
    运行

    ec_center.js

    1. const ec_center_option = {
    2. tooltip: {
    3. trigger: 'item',
    4. formatter: '名称:{a}
      省份:{b}
      确诊人数:{c}'
    5. },
    6. //左侧小导航图标
    7. visualMap: {
    8. show: true,
    9. x: 'left',
    10. y: 'bottom',
    11. textStyle: {
    12. fontSize: 8,
    13. color:['#FFFFFF']
    14. },
    15. splitList: [{ start: 0,end: 9 },
    16. {start: 10, end: 99 },
    17. { start: 100, end: 999 },
    18. { start: 1000, end: 9999 },
    19. { start: 10000 }],
    20. color: ['#8A3310', '#C64918', '#E55B25', '#F2AD92', '#F9DCD1']
    21. },
    22. series: [
    23. {
    24. name: '数据',
    25. type: 'map',
    26. mapType: 'china',
    27. roam: false,
    28. itemStyle: {
    29. normal: {
    30. borderWidth: .5, //区域边框宽度
    31. borderColor: '#62d3ff', //区域边框颜色
    32. areaColor: "#b7ffe6", //区域颜色
    33. label: { show: true }
    34. },
    35. emphasis: { //鼠标滑过地图高亮的相关设置
    36. borderWidth: .5,
    37. borderColor: '#fff',
    38. areaColor: "#fff",
    39. label: { show: true }
    40. }},
    41. data: [] // data_list
    42. }
    43. ]
    44. };
    45. ec_center = echarts.init(document.getElementById('main'));
    46. ec_center.setOption(ec_center_option)

    到这里第三板块就完成了!

    第四板块

    首先完成上面的柱状图

    utils.py

    1. def get_r1_data():
    2. """
    3. :return: 返回新增确诊人数前5名的省份
    4. """
    5. sql = '''
    6. SELECT province,confirm FROM
    7. (select province ,sum(confirm_add) as confirm from details
    8. where update_time=(select update_time from details
    9. order by update_time desc limit 1)
    10. group by province) as a
    11. ORDER BY confirm DESC LIMIT 7;
    12. '''
    13. res = query(sql)
    14. return res

    app.py

    1. @app.route('/r1')
    2. def get_r1_data():
    3. name,value = [],[]
    4. for n,v in utils.get_r1_data()[2:]:
    5. name.append(n)
    6. value.append(int(v))
    7. return jsonify({'name':name,'value':value})

    get_data.js

    1. function get_r1_data(){
    2. $.ajax({
    3. url:'/r1',
    4. success:function(data){
    5. ec_right1_option.xAxis.data=data.name
    6. ec_right1_option.series[0].data=data.value
    7. ec_right1.setOption(ec_right1_option)
    8. }
    9. });
    10. }
    '
    运行

    ec_right1.js

    1. var ec_right1 = echarts.init(document.getElementById('r1'),"dark");
    2. var ec_right1_option = {
    3. //标题样式
    4. title : {
    5. text : "新增确诊人数TOP5",
    6. textStyle : {
    7. color : 'white',
    8. },
    9. left : 'left'
    10. },
    11. color: ['#3398DB'],
    12. tooltip: {
    13. trigger: 'axis',
    14. axisPointer: { // 坐标轴指示器,坐标轴触发有效
    15. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
    16. }
    17. },
    18. xAxis: {
    19. type: 'category',
    20. color : 'white',
    21. data: []
    22. },
    23. yAxis: {
    24. type: 'value',
    25. color : 'white',
    26. },
    27. series: [{
    28. data: [],
    29. type: 'bar',
    30. barMaxWidth:"50%"
    31. }]
    32. };
    33. ec_right1.setOption(ec_right1_option)

    接着完成下面的词云图

    utils.py

    1. def get_r2_data():
    2. """
    3. :return: 返回最近的20条热搜
    4. """
    5. sql = 'select title from focu_news order by news_time desc limit 20'
    6. res = query(sql)
    7. all_word = ''
    8. for item in res:
    9. all_word += item[0]
    10. new_data = re.findall('[\u4e00-\u9fa5]+', all_word, re.S)
    11. new_data = "/".join(new_data)
    12. seg_list_exact = jieba.cut(new_data, cut_all=True)
    13. result_list = []
    14. with open('停用词库.txt', encoding='utf-8') as f:
    15. con = f.readlines()
    16. stop_words = set()
    17. for i in con:
    18. i = i.replace("\n", "") # 去掉读取每一行数据的\n
    19. stop_words.add(i)
    20. for word in seg_list_exact:
    21. if word not in stop_words and len(word) > 1:
    22. result_list.append(word)
    23. word_counts = collections.Counter(result_list)
    24. # 词频统计:获取前80最高频的词
    25. word_counts_top = word_counts.most_common(80)
    26. return word_counts_top

    app.py

    1. @app.route('/r2')
    2. def get_r2_data():
    3. data = utils.get_r2_data()
    4. d = []
    5. for i in data:
    6. k = i[0]
    7. v = int(i[1])
    8. d.append({"name": k, "value": v})
    9. return jsonify({"kws": d})

    get_data.py

    1. function get_r2_data() {
    2. $.ajax({
    3. url: "/r2",
    4. success: function (data) {
    5. ec_right2_option.series[0].data=data.kws;
    6. ec_right2.setOption(ec_right2_option);
    7. }
    8. })
    9. }
    '
    运行

    ec_right2.js

    1. var ec_right2 = echarts.init(document.getElementById('r2'), "dark");
    2. var ec_right2_option = {
    3. // backgroundColor: '#515151',
    4. title: {
    5. text: "微博热搜话题",
    6. textStyle: {
    7. color: 'white',
    8. },
    9. left: 'left'
    10. },
    11. tooltip: {
    12. show: false
    13. },
    14. series: [{
    15. type: 'wordCloud',
    16. // drawOutOfBound:true,
    17. gridSize: 1,
    18. sizeRange: [12, 55],
    19. rotationRange: [-45, 0, 45, 90],
    20. // maskImage: maskImage,
    21. textStyle: {
    22. normal: {
    23. color: function () {
    24. return 'rgb(' +
    25. Math.round(Math.random() * 255) +
    26. ', ' + Math.round(Math.random() * 255) +
    27. ', ' + Math.round(Math.random() * 255) + ')'
    28. }
    29. }
    30. },
    31. // left: 'center',
    32. // top: 'center',
    33. // // width: '96%',
    34. // // height: '100%',
    35. right: null,
    36. bottom: null,
    37. // width: 300,
    38. // height: 200,
    39. // top: 20,
    40. data: []
    41. }]
    42. }
    43. ec_right2.setOption(ec_right2_option);

    到这里,全部的页面及渲染就编写完成!

    4.添加定时任务

    这里忘记说了,前面每次在get_data.js中编写的函数,最后要调用才能使用

    1. get_c1_data()
    2. get_c2_data()
    3. get_l1_data()
    4. get_l2_data()
    5. get_r1_data()
    6. get_r2_data()

    这里我们还需要给定义发送请求的ajax函数设置定时,也就是在get_data.js里面添加

    1. setInterval(gettime,1000) # 时间是1s获取一次
    2. setInterval(get_c1_data,1000*60*60) # 1小时发送一次请求
    3. setInterval(get_c2_data,1000*60*60*6)
    4. setInterval(get_l1_data,1000*60*60*12)
    5. setInterval(get_l2_data,1000*60*60*12)
    6. setInterval(get_r1_data,1000*60*60*6)
    7. setInterval(get_r2_data,1000*10)

    项目总结

    本项目适合flask初学者来进行练手,当然前提也要会一些前端的知识,关于Echarts的使用可以去官网进行学习。关于页面的布局,可自由发挥来进行设计,或者在此基础上来进行创新,开发新的功能。

  • 相关阅读:
    Jackson ObjectMapper详解
    外汇天眼:ASIC年罚款收入高达2.299亿美元,难道是靠罚款吃饭?
    [晕事]今天做了件晕事31, gre 抓到半边
    2023-2024年最新大数据学习路线
    PHP 图书资料管理系统mysql数据库web结构apache计算机软件工程网页wamp
    Mybatis之动态sql和分页
    2022年C等级考试九月一级真题B:成绩判定
    记于2022.7.21
    Android Termux安装MySQL,内网穿透实现公网远程访问
    蓝牙核心规范(V5.4)12.4-深入详解之广播编码选择
  • 原文地址:https://blog.csdn.net/m0_64336780/article/details/126949053