gpt4 book ai didi

python - 无法在 pygal 折线图中设置宽度和高度

转载 作者:太空宇宙 更新时间:2023-11-04 00:20:01 24 4
gpt4 key购买 nike

我正在使用 flask 和 pygal 制作一个网站。

为了绘制图表,我将其放在我的网页中:

<div class="graph-area">
<div align="center">
<embed type="image/svg+xml" src={{graph_data|safe}} />
</div>
</div>
.graph-area{
margin-left:255px;
height:500px;
margin-bottom: 5px;
border-radius: 10px;
}
@app.route("/test")
def test():
custom_style = Style(
background='transparent',
plot_background='transparent',
foreground='#53E89B',
foreground_strong='#53A0E8',
foreground_subtle='#630C0D',
opacity='.6',
opacity_hover='.9',
transition='400ms ease-in')
graph = pygal.Line(width=500, height=400, style=custom_style)
graph.title = 'Food intake'
graph.x_labels = ['lundi','mardi','mercredi','jeudi','vendredi','samedi']
graph.add('Proteins', [15, 16, 17, 15, 10, 15])
graph.add('Lipids', [40, 45, 40, 42, 45, 42])
graph.add('Carbs', [21, 22, 22, 20, 18, 16])
graph.add('Net carbs', [12, 11, 11, 11, 10, 13])
graph_data = graph.render_data_uri()
return render_template("test.html", graph_data = graph_data)

宽高参数不作用于图(图很大,超过1500x1500)。我在 HTML 中做错了什么吗?

我知道我可以在图表上应用 CSS 样式,但我想使用 native pygal 解决方案。

最佳答案

如果我在图形构造函数中添加 explicit_size=True 就可以了

所以你得到:

graph = pygal.Line(width=500, height=400, explicit_size=True, style=custom_style)

请注意,图形大小将覆盖任何 css 缩放尝试,网页的其他部分不会根据图形进行缩放。

我不明白为什么必须添加它 (explicit_size),文档没有在尺寸示例中讨论它,但是没有它尺寸示例就不起作用。

关于python - 无法在 pygal 折线图中设置宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49463414/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com