Reputation: 39
I am new to Python, Django, and Plotly. I am trying to render a graph but I am unable to do so. The images below depict my problem. When my page loads it displays the graph as a set of characters of the sort. When I click F12 it shows the second image, just partially rendering the graph. I am not sure where I went wrong, I would really appreciate your help.
from plotly.offline import plot
import plotly.graph_objects as go
def home(request):
"""Renders the home page."""
valuesX = [];
valuesY = [];
results = DTH.objects.filter(date__gte = '2019-12-01', date__lte = '2019-12-31');
for row in results:
valuesX.append(row.date);
valuesY.append(row.price);
#fig = go.Figure([go.Scatter(x=[0,1,2,3], y=[0,1,2,3])]);
fig = go.Figure([go.Scatter(x=valuesX, y=valuesY)]);
plt_div = plot(fig, output_type='div', show_link=False, link_text="")
return render_to_response('app/index.html', { 'plt_div': plt_div })
Upvotes: 0
Views: 365
Reputation: 101
Try to update a layout of the graph by either setting its autosize paramether to True or providing the height and width of the graph
fig.update_layout(
autosize=True,
)
or
fig.update_layout(
autosize=False,
width=800,
height=500,
)
Upvotes: 1