You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
2.9 KiB
122 lines
2.9 KiB
from django.shortcuts import render, redirect
|
|
from django.http import JsonResponse
|
|
from app01 import models
|
|
|
|
|
|
def chart_list(request):
|
|
"""数据统计页面"""
|
|
return render(request, 'chart_list.html')
|
|
|
|
|
|
def chart_bar(request):
|
|
"""折线图"""
|
|
queryset = models.Department.objects.all()
|
|
legend = []
|
|
dict_count = {}
|
|
for i in queryset:
|
|
legend.append(i.title)
|
|
dict_count[i.title] = 0
|
|
queryset1 = models.UserInfo.objects.all()
|
|
for i in queryset1:
|
|
if i.depart.title in dict_count.keys():
|
|
dict_count[i.depart.title] += 1
|
|
else:
|
|
dict_count[i.depart.title] = 1
|
|
|
|
# legend = ['员工人数']
|
|
series = []
|
|
for i in queryset:
|
|
series.append({
|
|
"name": i.title, # 部门名称
|
|
"type": 'bar', # 类型为柱状图
|
|
"data": [dict_count[i.title]], # 员工人数
|
|
})
|
|
print("---series----")
|
|
print(series)
|
|
yAxis = [2, 4, 6, 8, 10, 12]
|
|
result = {
|
|
"status": True,
|
|
"data": {
|
|
"legend": legend,
|
|
"series": series,
|
|
"yAxis": yAxis
|
|
}
|
|
}
|
|
|
|
return JsonResponse(result)
|
|
|
|
|
|
def chart_line(request):
|
|
queryset = models.Department.objects.all()
|
|
legend = []
|
|
dict_count = {}
|
|
for i in queryset:
|
|
legend.append(i.title)
|
|
dict_count[i.title] = []
|
|
queryset1 = models.UserInfo.objects.all()
|
|
for i in queryset1:
|
|
if i.depart.title in dict_count.keys():
|
|
dict_count[i.depart.title].append(i.account)
|
|
|
|
for i in queryset:
|
|
print("值1")
|
|
for j in range(len(dict_count[i.title])):
|
|
dict_count[i.title][j] = float(dict_count[i.title][j])
|
|
|
|
for i in queryset:
|
|
print("改变值")
|
|
print(dict_count[i.title])
|
|
|
|
# legend = ['员工人数']
|
|
series = []
|
|
for i in queryset:
|
|
series.append({
|
|
"name": i.title, # 部门名称
|
|
"type": 'line', # 类型为柱状图
|
|
"stack": 'Total',
|
|
"data": dict_count[i.title], # 员工人数
|
|
})
|
|
print("---series----")
|
|
print(series)
|
|
print(series[0]["data"])
|
|
yAxis = [1000, 2000, 3000, 4000, 5000, 6000]
|
|
result = {
|
|
"status": True,
|
|
"data": {
|
|
"legend": legend,
|
|
"series": series,
|
|
"yAxis": yAxis
|
|
}
|
|
}
|
|
|
|
return JsonResponse(result)
|
|
|
|
|
|
def chart_Pie(request):
|
|
dict_count = {}
|
|
queryset1 = models.UserInfo.objects.all()
|
|
male = 0
|
|
famale = 0
|
|
for i in queryset1:
|
|
if i.gender == 1:
|
|
male += 1
|
|
else:
|
|
famale += 1
|
|
data1 = []
|
|
data1.append({"value": male, "name": '男'})
|
|
data1.append({"value": famale, "name": '女'})
|
|
print(data1)
|
|
# data: [
|
|
# {value: 1048, name: ''},
|
|
# {value: 735, name: 'Direct'},
|
|
#
|
|
# ],
|
|
result = {
|
|
"status": True,
|
|
"data": {
|
|
"data1": data1,
|
|
|
|
}
|
|
}
|
|
return JsonResponse(result)
|