效果:by部门展示人均建议数
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ae6d366c602148f8ed3d69ec1f71f4cf.png)
views.py
suggestion_all = suggestion.objects.all()
dept_review_all = dept_review.objects.all()
headcount_all = headcount.objects.all()
User_all = User.objects.all()
headcount_item = headcount_all.filter(Q(headcount_datetime__range=(start_date3, end_date3))).order_by('headcount_datetime').last()
print('headcount_item',headcount_item)
if headcount_item:
pass
else:
headcount_item = headcount_all.filter(Q(headcount_datetime__range=(this_year_start, this_year_end))).order_by('headcount_datetime').last()
headcount_ttl_count = headcount_item.headcount_ttl
print('headcount_item',headcount_item)
headcount_dict = {'总体':headcount_item.headcount_ttl,
'生产部':headcount_item.headcount_shengchanbu,
'物流部':headcount_item.headcount_wuliubu,
'人事综合管理部':headcount_item.headcount_renshizonghebu,
'工艺质量部':headcount_item.headcount_gongyizhiliangbu,
'项目部':headcount_item.headcount_xiangmubu,
'总经办':headcount_item.headcount_zongjingban,
'财务部':headcount_item.headcount_caiwubu,
'研发部':headcount_item.headcount_yanfabu,
}
person_average_suggestion = suggestion_count/headcount_ttl_count
suggestion_count = suggestion_all.filter(Q(suggestion_date__range=(start_date3, end_date3))).count()
list_of_suggestion_dept_count = []
dict_of_sum_suggestion_dept_count = {'总体':round(suggestion_count/headcount_ttl_count,1),
'生产部':0,
'物流部':0,
'人事综合管理部':0,
'工艺质量部':0,
'项目部':0,
'总经办':0,
'财务部':0,
'研发部':0,
}
for su in suggestion_all:
list_of_suggestion_dept_count.append(su.suggestion_employee_dept)
for suggestion_employee_dept in list_of_suggestion_dept_count:
dept_sum = suggestion_all.filter(Q(suggestion_employee_dept=suggestion_employee_dept) & Q(suggestion_date__range=(start_date1, end_date1))).aggregate(suggestion_employee_dept=Count('suggestion_employee_id'))
process_dict = {suggestion_employee_dept : round(dept_sum['suggestion_employee_dept']/headcount_dict[suggestion_employee_dept],1)}
dict_of_sum_suggestion_dept_count.update(process_dict)
value24A = []
value24B = []
for key,value in dict_of_sum_suggestion_dept_count.items():
value24A.append(key)
value24B.append(value)
dashboard.html
<div class="row p-2 pt-3 m-2 border">
<div class="col-12" id="main24" style="width: 300px;height:300px;">
<div id="main24" style="width: 90%;height:90%;"></div>
</div>
</div>
<script type="text/javascript">
var value24A_js = JSON.parse('{{ value24A|safe }}');
console.log('value24A_js',value24A_js);
var value24B_js = JSON.parse('{{ value24B|safe }}');
console.log('value24B_js',value24B_js);
var myChart = echarts.init(document.getElementById('main24'));
var option = {
title: {
text: '各部门人均合理化建议'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {
top: "10%",
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'value',
minInterval:0.1,
min: 0,
},
yAxis: {
type: 'category',
inverse: true,
data: value24A_js,
},
series: [
{
name: '提出数量',
type: 'bar',
data: value24B_js,
label: {
normal: {
show: true,
position: 'right'
},
formatter: '{@value}'
},
}
],
itemStyle: {
color: '#4169E1'
},
};
myChart.setOption(option);
</script>