IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> 今天的Django教训汇总:pyecharts和django融合,以雷达图为例-20211021 -> 正文阅读

[Python知识库]今天的Django教训汇总:pyecharts和django融合,以雷达图为例-20211021

成功将django和pyecharts初步融合

views.py


# Season尝试导入pyecharts表格

def page_draggable_layout(request,eid):

    # 创建雷达图
    c = (
        Radar()
        .add_schema(
            schema=[
                opts.RadarIndicatorItem(name="接纳反馈", max_=100),
                opts.RadarIndicatorItem(name="学习敏锐度", max_=100),
                opts.RadarIndicatorItem(name="结果导向", max_=100),
                opts.RadarIndicatorItem(name="全局思维", max_=100),
                opts.RadarIndicatorItem(name="适应力", max_=100),
                opts.RadarIndicatorItem(name="成就他人", max_=100),
                opts.RadarIndicatorItem(name="领导意愿", max_=100),
                opts.RadarIndicatorItem(name="平衡人际与任务", max_=100),
                opts.RadarIndicatorItem(name="辅导", max_=100),
                opts.RadarIndicatorItem(name="授权委责", max_=100),
                opts.RadarIndicatorItem(name="建立成功团队", max_=100),
                opts.RadarIndicatorItem(name="管理人际关系", max_=100),
                opts.RadarIndicatorItem(name="影响力", max_=100),
                opts.RadarIndicatorItem(name="建立伙伴关系", max_=100),
                opts.RadarIndicatorItem(name="计划与组织", max_=100),
            ],
            splitarea_opt=opts.SplitAreaOpts(
                is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
            ),
        )
        .set_global_opts(
            legend_opts=opts.LegendOpts(),
            title_opts=opts.TitleOpts(title="PP Test结果对比图"),
        )
        #.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    )

    employee_list = Employee.objects.filter(eid=eid)


    # 将员工数据写进去雷达图
    for employee in employee_list:
        v1=[]
        data_list = []
        data_list.append(employee.score_jieshoufankui)
        data_list.append(employee.score_xueximinruidu)
        data_list.append(employee.score_jieguodaoxiang)
        data_list.append(employee.score_quanjusiwei)
        data_list.append(employee.score_shiyingli)
        data_list.append(employee.score_chengjiutaren)
        data_list.append(employee.score_lingdaoyiyuan)                
        data_list.append(employee.score_pinghengrenjiyurenwu)
        data_list.append(employee.score_fudao)
        data_list.append(employee.score_shouquanweize)
        data_list.append(employee.score_jianlichenggongtuandui)
        data_list.append(employee.score_guanlirenjiguanxi)
        data_list.append(employee.score_yingxiangli)
        data_list.append(employee.score_jianlihuobanguanxi)
        data_list.append(employee.score_jihuayuzuzhi)

        #v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
        v1.append(data_list)
        c.add(series_name = employee.name, data = v1, label_opts=opts.LabelOpts(is_show=False))



    # 得出部门参考数据
    dept_code_ = employee_list.first().dept_code[:4] #部门代码取前4码
    print(dept_code_)
    dept_employee = Employee.objects.filter(dept_code__istartswith=dept_code_)
    score_jieshoufankui = dept_employee.aggregate(Avg('score_jieshoufankui'))
    score_xueximinruidu = dept_employee.aggregate(Avg('score_xueximinruidu'))
    score_jieguodaoxiang = dept_employee.aggregate(Avg('score_jieguodaoxiang'))
    score_quanjusiwei = dept_employee.aggregate(Avg('score_quanjusiwei'))
    score_shiyingli = dept_employee.aggregate(Avg('score_shiyingli'))
    score_chengjiutaren = dept_employee.aggregate(Avg('score_chengjiutaren'))
    score_lingdaoyiyuan = dept_employee.aggregate(Avg('score_lingdaoyiyuan'))
    score_pinghengrenjiyurenwu = dept_employee.aggregate(Avg('score_pinghengrenjiyurenwu'))
    score_fudao = dept_employee.aggregate(Avg('score_fudao'))
    score_shouquanweize = dept_employee.aggregate(Avg('score_shouquanweize'))
    score_jianlichenggongtuandui = dept_employee.aggregate(Avg('score_jianlichenggongtuandui'))
    score_guanlirenjiguanxi = dept_employee.aggregate(Avg('score_guanlirenjiguanxi'))
    score_yingxiangli = dept_employee.aggregate(Avg('score_yingxiangli'))
    score_jianlihuobanguanxi = dept_employee.aggregate(Avg('score_jianlihuobanguanxi'))
    score_jihuayuzuzhi = dept_employee.aggregate(Avg('score_jihuayuzuzhi'))



    # 将部门参考数据写进去雷达图
    if True:
        v2=[]
        data_list2 = []
        data_list2.append(score_jieshoufankui['score_jieshoufankui__avg'])
        data_list2.append(score_xueximinruidu['score_xueximinruidu__avg'])
        data_list2.append(score_jieguodaoxiang['score_jieguodaoxiang__avg'])
        data_list2.append(score_quanjusiwei['score_quanjusiwei__avg'])
        data_list2.append(score_shiyingli['score_shiyingli__avg'])
        data_list2.append(score_chengjiutaren['score_chengjiutaren__avg'])
        data_list2.append(score_lingdaoyiyuan['score_lingdaoyiyuan__avg'])                
        data_list2.append(score_pinghengrenjiyurenwu['score_pinghengrenjiyurenwu__avg'])
        data_list2.append(score_fudao['score_fudao__avg'])
        data_list2.append(score_shouquanweize['score_shouquanweize__avg'])
        data_list2.append(score_jianlichenggongtuandui['score_jianlichenggongtuandui__avg'])
        data_list2.append(score_guanlirenjiguanxi['score_guanlirenjiguanxi__avg'])
        data_list2.append(score_yingxiangli['score_yingxiangli__avg'])
        data_list2.append(score_jianlihuobanguanxi['score_jianlihuobanguanxi__avg'])
        data_list2.append(score_jihuayuzuzhi['score_jihuayuzuzhi__avg'])

        print(data_list2)
        #v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
        v2.append(data_list2)
        #c.add('部门平均水平', v2, color="#444693")
        c.add(series_name = '部门平均水平', data = v2, color="#444693", label_opts=opts.LabelOpts(is_show=False))




    # 得出厂处级参考数据
    plant_code_ = employee_list.first().dept_code[:3] #部门代码取前4码
    print(plant_code_)
    dept_employee = Employee.objects.filter(dept_code__istartswith=plant_code_)
    score_jieshoufankui = dept_employee.aggregate(Avg('score_jieshoufankui'))
    score_xueximinruidu = dept_employee.aggregate(Avg('score_xueximinruidu'))
    score_jieguodaoxiang = dept_employee.aggregate(Avg('score_jieguodaoxiang'))
    score_quanjusiwei = dept_employee.aggregate(Avg('score_quanjusiwei'))
    score_shiyingli = dept_employee.aggregate(Avg('score_shiyingli'))
    score_chengjiutaren = dept_employee.aggregate(Avg('score_chengjiutaren'))
    score_lingdaoyiyuan = dept_employee.aggregate(Avg('score_lingdaoyiyuan'))
    score_pinghengrenjiyurenwu = dept_employee.aggregate(Avg('score_pinghengrenjiyurenwu'))
    score_fudao = dept_employee.aggregate(Avg('score_fudao'))
    score_shouquanweize = dept_employee.aggregate(Avg('score_shouquanweize'))
    score_jianlichenggongtuandui = dept_employee.aggregate(Avg('score_jianlichenggongtuandui'))
    score_guanlirenjiguanxi = dept_employee.aggregate(Avg('score_guanlirenjiguanxi'))
    score_yingxiangli = dept_employee.aggregate(Avg('score_yingxiangli'))
    score_jianlihuobanguanxi = dept_employee.aggregate(Avg('score_jianlihuobanguanxi'))
    score_jihuayuzuzhi = dept_employee.aggregate(Avg('score_jihuayuzuzhi'))






    # 将厂处级参考数据写进去雷达图
    if True:
        v3=[]
        data_list3 = []
        data_list3.append(score_jieshoufankui['score_jieshoufankui__avg'])
        data_list3.append(score_xueximinruidu['score_xueximinruidu__avg'])
        data_list3.append(score_jieguodaoxiang['score_jieguodaoxiang__avg'])
        data_list3.append(score_quanjusiwei['score_quanjusiwei__avg'])
        data_list3.append(score_shiyingli['score_shiyingli__avg'])
        data_list3.append(score_chengjiutaren['score_chengjiutaren__avg'])
        data_list3.append(score_lingdaoyiyuan['score_lingdaoyiyuan__avg'])                
        data_list3.append(score_pinghengrenjiyurenwu['score_pinghengrenjiyurenwu__avg'])
        data_list3.append(score_fudao['score_fudao__avg'])
        data_list3.append(score_shouquanweize['score_shouquanweize__avg'])
        data_list3.append(score_jianlichenggongtuandui['score_jianlichenggongtuandui__avg'])
        data_list3.append(score_guanlirenjiguanxi['score_guanlirenjiguanxi__avg'])
        data_list3.append(score_yingxiangli['score_yingxiangli__avg'])
        data_list3.append(score_jianlihuobanguanxi['score_jianlihuobanguanxi__avg'])
        data_list3.append(score_jihuayuzuzhi['score_jihuayuzuzhi__avg'])

        print(data_list3)
        #v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
        v3.append(data_list3)
        #c.add('厂处平均水平', v3, color="#1d953f")
        c.add(series_name = '厂处平均水平', data = v3, color="#1d953f", label_opts=opts.LabelOpts(is_show=False))
        
    


    grid = (
    Grid()
    .add(c, grid_opts=opts.GridOpts(pos_right="80%"))
    #.add(d, grid_opts=opts.GridOpts(pos_left="80%"))
    )

    return HttpResponse(grid.render_embed())

urls.py

from django.urls import path
from django.conf.urls import url

from . import views

urlpatterns = [
    path('', views.index, name='index'),
    path('search_results/', views.search_results, name='search_results'),
    path('search_results2/', views.search_results2, name='search_results2'),
    path('search_results/<eid>/', views.search_results_detail, name='search_results_detail'),
    path('page_draggable_layout/<eid>/',views.page_draggable_layout,name='page_draggable_layout'),
]

models.py

from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator 


# Create your models here.
class Employee(models.Model):
    eid = models.CharField(max_length=200,null=True)
    name = models.CharField(max_length=200,null=True)
    dept_code = models.CharField(max_length=200,null=True)
    level_opt = (
        (u'课级', u'课级'),
        (u'部级', u'部级'),
    )
    level = models.CharField(max_length=200,choices=level_opt,null=True)
    function_opt = (
        (u'工程类', u'工程类'),
        (u'生产类', u'生产类'),
        (u'品质类', u'品质类'),
        (u'资材类', u'资材类'),
        (u'托管', u'托管'),
        (u'其他', u'其他'),
    )   
    function = models.CharField(max_length=200,choices=function_opt,null=True)
    batch_opt = (
        (u'WZS-P1', u'WZS-P1'),
        (u'WZS-P3', u'WZS-P3'),
        (u'WZS-P6', u'WZS-P6'),
        (u'WZS-WT其他', u'WZS-WT其他'),
    )   
    batch = models.CharField(max_length=200,choices=batch_opt,null=True)
    mail = models.CharField(max_length=200,null=True, verbose_name=r'邮箱地址',)
    score_jieshoufankui = models.IntegerField(default=0, verbose_name=r'接纳反馈', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_xueximinruidu = models.IntegerField(default=0, verbose_name=r'学习敏锐度', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_jieguodaoxiang = models.IntegerField(default=0, verbose_name=r'结果导向', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_quanjusiwei = models.IntegerField(default=0, verbose_name=r'全局思维', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_shiyingli = models.IntegerField(default=0, verbose_name=r'适应力', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_chengjiutaren = models.IntegerField(default=0, verbose_name=r'成就他人', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_lingdaoyiyuan = models.IntegerField(default=0, verbose_name=r'领导意愿', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_pinghengrenjiyurenwu = models.IntegerField(default=0, verbose_name=r'平衡人际与任务', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_fudao = models.IntegerField(default=0, verbose_name=r'辅导', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_shouquanweize = models.IntegerField(default=0, verbose_name=r'授权委责', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_jianlichenggongtuandui = models.IntegerField(default=0, verbose_name=r'建立成功团队', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_guanlirenjiguanxi = models.IntegerField(default=0, verbose_name=r'管理人际关系', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_yingxiangli = models.IntegerField(default=0, verbose_name=r'影响力', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_jianlihuobanguanxi = models.IntegerField(default=0, verbose_name=r'建立伙伴关系', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')
    score_jihuayuzuzhi = models.IntegerField(default=0, verbose_name=r'计划与组织', validators=[MinValueValidator(0), MaxValueValidator(100)],help_text='请输入0-100的整数')


    def __str__(self):
        return str(self.name)



# 定义后台上传Employee文件的接口
class Import_Employee(models.Model):
    file = models.FileField(upload_to='file')
    name = models.CharField(max_length=50,verbose_name=r'文件名')

    class Meta:
        ordering = ['name']

    def __str__(self):
        return str(self.name)

templates使用pyecharts默认模板

{% 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>

在这里插入图片描述

  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2021-10-22 10:53:42  更:2021-10-22 10:55:26 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 21:46:47-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码