如何解决matplotlib python 列表全面吗?
我想做一个简单的图表来显示每天所有约会的总利润。结果显示类似的东西 这绝对是不对的。 我知道这个问题在我的 views.py 列表中很全面,但不知道如何解决它.. 任何帮助表示赞赏
models.py
class Service(models.Model):
service_name = models.CharField(max_length=50)
service_price = models.DecimalField(max_digits=8,decimal_places=2)
physician = models.ForeignKey('Physician',on_delete=models.CASCADE)
def __str__(self):
return self.service_name
class Appointment(models.Model):
appointment_date = models.DateField(null=True)
appointment_time = models.TimeField(null=True)
patient = models.ForeignKey('Patient',on_delete=models.CASCADE)
reseptionist = models.ForeignKey('Reseptionist',on_delete=models.SET_NULL,blank=True,null=True)
service = models.ForeignKey('Service',on_delete=models.CASCADE)
physician = models.ForeignKey('Physician',on_delete=models.CASCADE)
plots.py
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import base64
from io import BytesIO
def get_graph():
buffer = BytesIO()
plt.savefig(buffer,format="png")
buffer.seek(0)
img = buffer.getvalue()
g = base64.b64encode(img)
g = g.decode("utf-8")
buffer.close()
return g
def line_plot(x,y):
plt.figure(figsize=(4,4))
plt.plot(x,y)
return get_graph()
views.py
from .plots import line_plot
def index(request):
prices = Appointment.objects.all()
revenue = [x.service.service_price for x in prices]
day = [x.appointment_date for x in prices ]
c = pie_plot(revenue,day)
context = {'chart': c }
return render(request,'index.html',context)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。