Browse Source

feat: 网页新增数据分析

SongZihuan 3 years ago
parent
commit
702bbc6be6

+ 0 - 0
app/data/__init__.py


+ 94 - 0
app/data/views.py

@@ -0,0 +1,94 @@
+import pyecharts
+from flask import render_template, Blueprint, Flask, abort
+from jinja2 import Markup
+import datetime
+
+from tool.color import random_color
+from tool.typing import Optional
+from core.garbage import GarbageType
+
+from app import views
+
+data = Blueprint("data", __name__)
+app: Optional[Flask] = None
+init_opts = pyecharts.options.InitOpts(page_title="HGSSystem-统计",
+                                       width="1000px",
+                                       height="500px")
+
+
+@data.route('/')
+def index():
+    return render_template("data/data.html")
+
+
+@data.route('/pyecharts/count_by_day')
+def count_by_days():
+    db_data = views.website.count_by_days()
+    bar = pyecharts.charts.Bar(init_opts=init_opts)
+
+    res = {}
+    loc_type = []
+    count_data = [0] * 24
+    for i in db_data:
+        name = GarbageType.GarbageTypeStrList_ch[int(i[0].decode('utf-8'))]
+        if name not in loc_type:
+            loc_type.append(name)
+        lst = res.get(name, list())
+        lst.append(i[2])
+        count_data[int(i[1])] += i[2]
+        res[name] = lst
+
+    (bar.add_xaxis(xaxis_data=[f"{i}h" for i in range(24)])
+     .set_global_opts(xaxis_opts=pyecharts.options.AxisOpts(type_="category"),
+                      title_opts=pyecharts.options.TitleOpts(title="时段统计")))
+
+    for i in res:
+        bar.add_yaxis(series_name=i, y_axis=res[i], color=random_color())
+    bar.add_yaxis(series_name="合计", y_axis=count_data, color=random_color())
+
+    return Markup(bar.render_embed())
+
+
+@data.route('/pyecharts/count_by_date/<int:days>')
+def count_by_date(days):
+    if days != 7 and days != 30:
+        abort(404)
+
+    db_data = views.website.count_by_times(days)
+    line = pyecharts.charts.Line(init_opts=init_opts)
+    print(db_data)
+    res = {}
+    loc_type = []
+    count_data = [0] * days
+    for i in db_data:
+        name = GarbageType.GarbageTypeStrList_ch[int(i[0].decode('utf-8'))]
+        if name not in loc_type:
+            loc_type.append(name)
+        lst = res.get(name, [0] * days)
+        lst[int(i[1])] = i[2]
+        count_data[int(i[1])] += i[2]
+        res[name] = lst
+
+    x_label = []
+    end_time = datetime.datetime.now()
+    for i in range(days - 1, -1, -1):
+        d = end_time - datetime.timedelta(days=i)
+        x_label.append(d.strftime("%Y-%m-%d"))
+
+    (line.add_xaxis(xaxis_data=x_label)
+     .set_global_opts(xaxis_opts=pyecharts.options.AxisOpts(type_="category"),
+                      title_opts=pyecharts.options.TitleOpts(title=f"{days}日统计")))
+
+    for i in res:
+        y_data = res[i][::-1]  # 反转数据
+        line.add_yaxis(series_name=i, y_axis=y_data, color=random_color())
+    line.add_yaxis(series_name="合计", y_axis=count_data, color=random_color())
+
+    return Markup(line.render_embed())
+
+
+def creat_data_website(app_: Flask):
+    global app
+    if app is None:
+        app = app_
+        app.register_blueprint(data, url_prefix="/data")

+ 15 - 0
app/static/styles/data/data.css

@@ -0,0 +1,15 @@
+.pyecharts-frame {
+    width: 100%;
+    height: 550px;
+    border: 0;
+}
+
+.title {
+    margin-top: 20px;
+    font-size: 23px;
+}
+
+.info {
+    text-indent: 2em;
+    font-size: 19px;
+}

+ 3 - 0
app/templates/base.html

@@ -52,6 +52,9 @@
             <li class="nav-top-item"><a class="nav-top-item" href="{{ url_for('news.index', page=1) }}">
                 博客 </a></li>
 
+            <li class="nav-top-item"><a class="nav-top-item" href="{{ url_for('data.index', page=1) }}">
+                统计 </a></li>
+
             {% if current_user.is_authenticated %}
                 <li class="nav-top-item"><a class="nav-top-item" href="{{ url_for('auth.about') }}">
                     关于: {{ current_user.name }} </a></li>

+ 21 - 0
app/templates/data/data.html

@@ -0,0 +1,21 @@
+{% extends "base.html" %}
+
+{% block style %}
+    {{ super() }}
+    <link href="{{ url_for('static', filename='styles/data/data.css') }}" rel="stylesheet">
+{% endblock %}
+
+{% block title %} 数据分析 {% endblock %}
+{% block h1_title %} 数据分析 {% endblock %}
+
+{% block content %}
+    <h2 class="title"> 按时段统计垃圾量 </h2>
+    <p class="info"> 将数据库中的所有数据按时间段(小时)进行分类,然后获取统计值。 </p>
+    <iframe class="pyecharts-frame" src="{{ url_for("data.count_by_days") }}"></iframe>
+
+    <br>
+    <h2 class="title"> 按日期统计垃圾量 </h2>
+    <p class="info"> 将数据库中的所有数据按日期进行分类,然后获取统计值。 </p>
+    <iframe class="pyecharts-frame" src="{{ url_for("data.count_by_date", days=7) }}"></iframe>
+    <iframe class="pyecharts-frame" src="{{ url_for("data.count_by_date", days=30) }}"></iframe>
+{% endblock %}

+ 13 - 0
app/templates/data/pyecharts/components.html

@@ -0,0 +1,13 @@
+{% import 'macro' as macro %}
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title>{{ chart.page_title }}</title>
+</head>
+<body>
+
+{{ macro.gen_components_content(chart) }}
+
+</body>
+</html>

+ 195 - 0
app/templates/data/pyecharts/macro

@@ -0,0 +1,195 @@
+{%- macro render_chart_content(c) -%}
+    <div id="{{ c.chart_id }}" class="chart-container" style="width:{{ c.width }}; height:{{ c.height }};"></div>
+    <script>
+        var chart_{{ c.chart_id }} = echarts.init(
+            document.getElementById('{{ c.chart_id }}'), '{{ c.theme }}', {renderer: '{{ c.renderer }}'});
+        {% for js in c.js_functions.items %}
+            {{ js }}
+        {% endfor %}
+        var option_{{ c.chart_id }} = {{ c.json_contents }};
+        chart_{{ c.chart_id }}.setOption(option_{{ c.chart_id }});
+        {% if c._is_geo_chart %}
+            var bmap = chart_{{ c.chart_id }}.getModel().getComponent('bmap').getBMap();
+            {% if c.bmap_js_functions %}
+                {% for fn in c.bmap_js_functions.items %}
+                    {{ fn }}
+                {% endfor %}
+            {% endif %}
+        {% endif %}
+        {% if c.width.endswith('%') %}
+            window.addEventListener('resize', function(){
+                chart_{{ c.chart_id }}.resize();
+            })
+        {% endif %}
+    </script>
+{%- endmacro %}
+
+{%- macro render_notebook_charts(charts, libraries) -%}
+    <script>
+        require([{{ libraries | join(', ') }}], function(echarts) {
+        {% for c in charts %}
+            {% if c._component_type not in ("table", "image") %}
+                var chart_{{ c.chart_id }} = echarts.init(
+                    document.getElementById('{{ c.chart_id }}'), '{{ c.theme }}', {renderer: '{{ c.renderer }}'});
+                {% for js in c.js_functions.items %}
+                    {{ js }}
+                {% endfor %}
+                var option_{{ c.chart_id }} = {{ c.json_contents }};
+                chart_{{ c.chart_id }}.setOption(option_{{ c.chart_id }});
+                {% if c._is_geo_chart %}
+                    var bmap = chart_{{ c.chart_id }}.getModel().getComponent('bmap').getBMap();
+                    bmap.addControl(new BMap.MapTypeControl());
+                {% endif %}
+            {% endif %}
+        {% endfor %}
+        });
+    </script>
+{%- endmacro %}
+
+{%- macro render_chart_dependencies(c) -%}
+    {% for dep in c.dependencies %}
+        <script type="text/javascript" src="{{ dep }}"></script>
+    {% endfor %}
+{%- endmacro %}
+
+{%- macro render_chart_css(c) -%}
+    {% for dep in c.css_libs %}
+        <link rel="stylesheet"  href="{{ dep }}">
+    {% endfor %}
+{%- endmacro %}
+
+{%- macro display_tablinks(chart) -%}
+    <div class="tab">
+        {% for c in chart %}
+            <button class="tablinks" onclick="showChart(event, '{{ c.chart_id }}')">{{ c.tab_name }}</button>
+        {% endfor %}
+    </div>
+{%- endmacro %}
+
+{%- macro switch_tabs() -%}
+    <script>
+        (function() {
+            containers = document.getElementsByClassName("chart-container");
+            if(containers.length > 0) {
+                containers[0].style.display = "block";
+            }
+        })()
+
+        function showChart(evt, chartID) {
+            let containers = document.getElementsByClassName("chart-container");
+            for (let i = 0; i < containers.length; i++) {
+                containers[i].style.display = "none";
+            }
+
+            let tablinks = document.getElementsByClassName("tablinks");
+            for (let i = 0; i < tablinks.length; i++) {
+                tablinks[i].className = "tablinks";
+            }
+
+            document.getElementById(chartID).style.display = "block";
+            evt.currentTarget.className += " active";
+        }
+    </script>
+{%- endmacro %}
+
+{%- macro generate_tab_css() %}
+    <style>
+        .tab {
+            overflow: hidden;
+            border: 1px solid #ccc;
+            background-color: #f1f1f1;
+        }
+
+        .tab button {
+            background-color: inherit;
+            float: left;
+            border: none;
+            outline: none;
+            cursor: pointer;
+            padding: 12px 16px;
+            transition: 0.3s;
+        }
+
+        .tab button:hover {
+            background-color: #ddd;
+        }
+
+        .tab button.active {
+            background-color: #ccc;
+        }
+
+        .chart-container {
+            display: none;
+            padding: 6px 12px;
+            border-top: none;
+        }
+    </style>
+{%- endmacro %}
+
+{%- macro gen_components_content(chart) %}
+    {% if chart._component_type == "table" %}
+        <style>
+            .fl-table {
+                margin: 20px;
+                border-radius: 5px;
+                font-size: 12px;
+                border: none;
+                border-collapse: collapse;
+                max-width: 100%;
+                white-space: nowrap;
+                word-break: keep-all;
+            }
+
+            .fl-table th {
+                text-align: left;
+                font-size: 20px;
+            }
+
+            .fl-table tr {
+                display: table-row;
+                vertical-align: inherit;
+                border-color: inherit;
+            }
+
+            .fl-table tr:hover td {
+                background: #00d1b2;
+                color: #F8F8F8;
+            }
+
+            .fl-table td, .fl-table th {
+                border-style: none;
+                border-top: 1px solid #dbdbdb;
+                border-left: 1px solid #dbdbdb;
+                border-bottom: 3px solid #dbdbdb;
+                border-right: 1px solid #dbdbdb;
+                padding: .5em .55em;
+                font-size: 15px;
+            }
+
+            .fl-table td {
+                border-style: none;
+                font-size: 15px;
+                vertical-align: center;
+                border-bottom: 1px solid #dbdbdb;
+                border-left: 1px solid #dbdbdb;
+                border-right: 1px solid #dbdbdb;
+                height: 30px;
+            }
+
+            .fl-table tr:nth-child(even) {
+                background: #F8F8F8;
+            }
+        </style>
+        <div id="{{ chart.chart_id }}" class="chart-container" style="">
+            <p class="title" {{ chart.title_opts.title_style }}> {{ chart.title_opts.title }}</p>
+            <p class="subtitle" {{ chart.title_opts.subtitle_style }}> {{ chart.title_opts.subtitle }}</p>
+            {{ chart.html_content }}
+        </div>
+    {% elif chart._component_type == "image" %}
+        <div id="{{ chart.chart_id }}" class="chart-container" style="">
+            <p class="title" {{ chart.title_opts.title_style }}> {{ chart.title_opts.title }}</p>
+            <p class="subtitle" {{ chart.title_opts.subtitle_style }}> {{ chart.title_opts.subtitle }}</p>
+            <img {{ chart.html_content }}/>
+        </div>
+    {% endif %}
+{%- endmacro %}

+ 5 - 0
app/templates/data/pyecharts/nb_components.html

@@ -0,0 +1,5 @@
+{% import 'macro' as macro %}
+
+{% for chart in charts %}
+    {{ macro.gen_components_content(chart) }}
+{% endfor %}

+ 46 - 0
app/templates/data/pyecharts/nb_jupyter_globe.html

@@ -0,0 +1,46 @@
+<script>
+    require.config({
+        paths: {
+            {{ config_items | join(', ') }}
+        }
+    });
+</script>
+
+{% for chart in charts %}
+    <div id="{{ chart.chart_id }}" style="width:{{ chart.width }}; height:{{ chart.height }};"></div>
+{% endfor %}
+
+
+<script>
+    require([{{ libraries | join(', ') }}], function (echarts) {
+        {% for c in charts %}
+            var canvas_{{ c.chart_id }} = document.createElement('canvas');
+            var mapChart_{{ c.chart_id }} = echarts.init(
+                canvas_{{ c.chart_id }}, '{{ c.theme }}', {width: 4096, height: 2048, renderer: '{{ c.renderer }}'});
+            var mapOption_{{ c.chart_id }} = {{ c.json_contents }};
+            mapChart_{{ c.chart_id }}.setOption(mapOption_{{ c.chart_id }});
+            var chart_{{ c.chart_id }} = echarts.init(
+                document.getElementById('{{ c.chart_id }}'), '{{ c.theme }}', {renderer: '{{ c.renderer }}'});
+            {% for js in c.js_functions.items %}
+                {{ js }}
+            {% endfor %}
+            var option_{{ c.chart_id }} = {
+                "globe": {
+                    "show": true,
+                    "baseTexture": mapChart_{{ c.chart_id }},
+                    shading: 'lambert',
+                    light: {
+                        ambient: {
+                            intensity: 0.6
+                        },
+                        main: {
+                            intensity: 0.2
+                        }
+                    }
+
+                }
+            };
+            chart_{{ c.chart_id }}.setOption(option_{{ c.chart_id }});
+        {% endfor %}
+    });
+</script>

+ 16 - 0
app/templates/data/pyecharts/nb_jupyter_lab.html

@@ -0,0 +1,16 @@
+{% import 'macro' as macro %}
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+</head>
+<body>
+{% for chart in charts %}
+    {% if chart._component_type in ("table", "image") %}
+        {{ macro.gen_components_content(chart) }}
+    {% else %}
+        {{ macro.render_chart_content(chart) }}
+    {% endif %}
+{% endfor %}
+</body>
+</html>

+ 20 - 0
app/templates/data/pyecharts/nb_jupyter_lab_tab.html

@@ -0,0 +1,20 @@
+{% import 'macro' as macro %}
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+</head>
+<body>
+{{ macro.generate_tab_css() }}
+{{ macro.display_tablinks(charts) }}
+
+{% for chart in charts %}
+    {% if chart._component_type in ("table", "image") %}
+        {{ macro.gen_components_content(chart) }}
+    {% else %}
+        {{ macro.render_chart_content(chart) }}
+    {% endif %}
+{% endfor %}
+{{ macro.switch_tabs() }}
+</body>
+</html>

+ 19 - 0
app/templates/data/pyecharts/nb_jupyter_notebook.html

@@ -0,0 +1,19 @@
+{% import 'macro' as macro %}
+
+<script>
+    require.config({
+        paths: {
+            {{ config_items | join(', ') }}
+        }
+    });
+</script>
+
+{% for chart in charts %}
+    {% if chart._component_type in ("table", "image") %}
+        {{ macro.gen_components_content(chart) }}
+    {% else %}
+        <div id="{{ chart.chart_id }}" style="width:{{ chart.width }}; height:{{ chart.height }};"></div>
+    {% endif %}
+{% endfor %}
+
+{{ macro.render_notebook_charts(charts, libraries) }}

+ 24 - 0
app/templates/data/pyecharts/nb_jupyter_notebook_tab.html

@@ -0,0 +1,24 @@
+{% import 'macro' as macro %}
+
+<script>
+    require.config({
+        paths: {
+            {{ config_items | join(', ') }}
+        }
+    });
+</script>
+
+{{ macro.generate_tab_css() }}
+{{ macro.display_tablinks(charts) }}
+
+{% for chart in charts %}
+    {% if chart._component_type in ("table", "image") %}
+        {{ macro.gen_components_content(chart) }}
+    {% else %}
+        <div id="{{ chart.chart_id }}" class="chart-container"
+             style="width:{{ chart.width }}; height:{{ chart.height }};"></div>
+    {% endif %}
+{% endfor %}
+
+{{ macro.render_notebook_charts(charts, libraries) }}
+{{ macro.switch_tabs() }}

+ 13 - 0
app/templates/data/pyecharts/nb_nteract.html

@@ -0,0 +1,13 @@
+{% import 'macro' as macro %}
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+    {{ macro.render_chart_dependencies(chart) }}
+</head>
+<body>
+{% for c in chart %}
+    {{ macro.render_chart_content(c) }}
+{% endfor %}
+</body>
+</html>

+ 12 - 0
app/templates/data/pyecharts/simple_chart.html

@@ -0,0 +1,12 @@
+{% import 'macro' as macro %}
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title>{{ chart.page_title }}</title>
+    {{ macro.render_chart_dependencies(chart) }}
+</head>
+<body>
+{{ macro.render_chart_content(chart) }}
+</body>
+</html>

+ 46 - 0
app/templates/data/pyecharts/simple_globe.html

@@ -0,0 +1,46 @@
+{% import 'macro' as macro %}
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title>{{ chart.page_title }}</title>
+    {{ macro.render_chart_dependencies(chart) }}
+</head>
+<body>
+<div id="{{ chart.chart_id }}" style="width:{{ chart.width }}; height:{{ chart.height }};"></div>
+<script>
+    var canvas_{{ chart.chart_id }} = document.createElement('canvas');
+    var mapChart_{{ chart.chart_id }} = echarts.init(
+        canvas_{{ chart.chart_id }}, '{{ chart.theme }}', {
+            width: 4096,
+            height: 2048,
+            renderer: '{{ chart.renderer }}'
+        });
+    {% for js in chart.js_functions.items %}
+        {{ js }}
+    {% endfor %}
+    var mapOption_{{ chart.chart_id }} = {{ chart.json_contents }};
+    mapChart_{{ chart.chart_id }}.setOption(mapOption_{{ chart.chart_id }});
+
+    var chart_{{ chart.chart_id }} = echarts.init(
+        document.getElementById('{{ chart.chart_id }}'), '{{ chart.theme }}', {renderer: '{{ chart.renderer }}'});
+    var options_{{ chart.chart_id }} = {
+        "globe": {
+            "show": true,
+            "baseTexture": mapChart_{{ chart.chart_id }},
+            shading: 'lambert',
+            light: {
+                ambient: {
+                    intensity: 0.6
+                },
+                main: {
+                    intensity: 0.2
+                }
+            }
+
+        }
+    };
+    chart_{{ chart.chart_id }}.setOption(options_{{ chart.chart_id }});
+</script>
+</body>
+</html>

+ 35 - 0
app/templates/data/pyecharts/simple_page.html

@@ -0,0 +1,35 @@
+{% import 'macro' as macro %}
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title>{{ chart.page_title }}</title>
+    {{ macro.render_chart_dependencies(chart) }}
+    {{ macro.render_chart_css(chart) }}
+</head>
+<body>
+<style>.box {
+{{ chart.layout }}
+}
+
+; </style>
+{% if chart.download_button %}
+    <button onclick="downloadCfg()">Save Config</button>
+{% endif %}
+<div class="box">
+    {% for c in chart %}
+        {% if c._component_type in ("table", "image") %}
+            {{ macro.gen_components_content(c) }}
+        {% else %}
+            {{ macro.render_chart_content(c) }}
+        {% endif %}
+        {% for _ in range(chart.page_interval) %}<br/>{% endfor %}
+    {% endfor %}
+</div>
+<script>
+    {% for js in chart.js_functions.items %}
+        {{ js }}
+    {% endfor %}
+</script>
+</body>
+</html>

+ 31 - 0
app/templates/data/pyecharts/simple_tab.html

@@ -0,0 +1,31 @@
+{% import 'macro' as macro %}
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title>{{ chart.page_title }}</title>
+    {{ macro.render_chart_dependencies(chart) }}
+    {{ macro.render_chart_css(chart) }}
+</head>
+<body>
+{{ macro.generate_tab_css() }}
+{{ macro.display_tablinks(chart) }}
+
+<div class="box">
+    {% for c in chart %}
+        {% if c._component_type in ("table", "image") %}
+            {{ macro.gen_components_content(c) }}
+        {% else %}
+            {{ macro.render_chart_content(c) }}
+        {% endif %}
+    {% endfor %}
+</div>
+
+<script>
+    {% for js in chart.js_functions.items %}
+        {{ js }}
+    {% endfor %}
+</script>
+{{ macro.switch_tabs() }}
+</body>
+</html>

+ 2 - 0
app/views.py

@@ -4,6 +4,7 @@ from app.rank.views import creat_ranking_website
 from app.auth.views import creat_auth_website
 from app.store.views import creat_store_website
 from app.news.views import creat_news_website
+from app.data.views import creat_data_website
 
 from tool.typing import *
 from sql.db import DB
@@ -25,3 +26,4 @@ def register(app: Flask, db: DB):
     creat_auth_website(app)
     creat_store_website(app)
     creat_news_website(app)
+    creat_data_website(app)

+ 19 - 1
app/web.py

@@ -145,6 +145,24 @@ class NewsWebsite(WebsiteBase):
         return delete_news(context_id, self._db)
 
 
-class Website(AuthWebsite, StoreWebsite, RankWebsite, NewsWebsite, WebsiteBase):
+class DataWebsite(WebsiteBase):
+    def count_by_days(self):
+        cur = self._db.search(columns=["GarbageType", "DATE_FORMAT(UseTime,'%H') AS days", "count(GarbageID) AS count"],
+                              table="garbage",
+                              group_by=["GarbageType", "days"],
+                              order_by=[("GarbageType", "ASC"), ("days", "ASC")],
+                              where="UseTime IS NOT NULL")
+        return cur.fetchall()
+
+    def count_by_times(self, days):
+        cur = self._db.search(columns=["GarbageType", "days", "count(GarbageID) AS count"],
+                              table=f"garbage_{days}d",
+                              group_by=["GarbageType", "days"],
+                              order_by=[("GarbageType", "ASC"), ("days", "ASC")],
+                              where="UseTime IS NOT NULL")
+        return cur.fetchall()
+
+
+class Website(AuthWebsite, StoreWebsite, RankWebsite, NewsWebsite, DataWebsite, WebsiteBase):
     def __init__(self, app: Flask, db: DB):
         super(Website, self).__init__(app, db)

+ 1 - 0
init.py

@@ -56,6 +56,7 @@ check_import("flask", "Flask")  # 网页服务
 check_import("flask", "Flask")  # 网页服务
 check_import("flask_wtf", "Flask-WTF")  # 网页服务
 check_import("flask_login", "Flask-Login")  # 网页服务
+check_import("pyecharts", "pyecharts")  # 网页服务
 check_import("waitress", "waitress")  # waitress 网页服务
 check_import("PIL", "Pillow")  # 图片处理
 check_import("numpy", "numpy")  # matplotlib依赖

+ 3 - 4
tk_ui/admin_program.py

@@ -2699,7 +2699,7 @@ class StatisticsDateProgramBase(StatisticsTimeProgramBase):
         max_y_plot = 1  # max_y的最大值
         max_y_bar = 1  # max_y的最大值
         for res_type in res_type_lst:
-            res_count: Tuple[str] = res[res_type]
+            res_count: List[Tuple[int, int, bytes]] = res[res_type]  # 距离今天的日期, 统计值, 分类值
             if len(res_count) != 0:
                 color = self.check_show(res_type)
                 if color is None:
@@ -2707,9 +2707,8 @@ class StatisticsDateProgramBase(StatisticsTimeProgramBase):
 
                 y = [0 for _ in range(self._days)]
                 for i in range(0, len(res_count)):  # 反向迭代列表
-                    index = self._days - res_count[i - 1][0] - 1  # 反向排序
-                    y[index] += int(res_count[i - 1][1])
-
+                    y[res_count[i][0]] = res_count[i][1]
+                y = y[::-1]  # 反转列表, 使距离今天小的数据靠数据轴右侧
                 max_y_plot = max(max(y), max_y_plot)
                 self.color_show_dict[res_type] = color
                 self.plt_1.plot(label_num, y,