简体   繁体   English

绘图显示字符而不是渲染图形

[英]Plotly showing characters not rendering graph

I am new to Python, Django, and Plotly.我是 Python、Django 和 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.当我单击 F12 时,它显示第二个图像,只是部分渲染图形。 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 })

图一:情节渲染的角色

图二:点击 F12 时会显示这个

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尝试通过将其 autosize 参数设置为 True 或提供图形的高度和宽度来更新图形的布局

fig.update_layout(
    autosize=True,
)

or或者

fig.update_layout(
    autosize=False,
    width=800,
    height=500,
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM