问题描述
我想做一个简单的图表来显示每天所有约会的总利润。结果显示类似的东西 这绝对是不对的。 我知道这个问题在我的 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 (将#修改为@)