I am trying to create a dashboard where I can analyse my model's data (Article) using the library plotly.
The Plotly bar chart is not showing on my template, I am wondering if I am doing something wrong since there's no error with the code below :
models.py
from django.db import models
from django.contrib.auth.models import User
import plotly.plotly as py
import plotly.graph_objs as go
class Article(models.Model):
user = models.ForeignKey(User, default='1')
titre = models.CharField(max_length=100, unique=True)
slug = models.SlugField(max_length=40)
likes = models.ManyToManyField(User, related_name="likes")
def __str__(self):
return self.titre
@property
def article_chart(self):
data = [
go.Bar(
x=[self.titre], #title of the article
y=[self.likes.count()] #number of likes on an article
)
]
plot_url = py.plot(data, filename='basic-bar')
return plot_url
dashboard.html
<div>{{ article.article_chart }}</div>
Why is the bar chart not visible? Any suggestion ?
article_chart
is a property ofArticle
, so you'll need to reference it as{{ article.article_chart }}
in your template. – Franey Jan 29 '16 at 20:51