【问题标题】:Can't set the width and height in a pygal line graph无法在 pygal 折线图中设置宽度和高度
【发布时间】:2018-09-02 22:36:59
【问题描述】:

我正在使用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)

width和height参数对图表没有作用(图表很大,超过1500x1500)。我在 HTML 中做错了吗?

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

【问题讨论】:

    标签: python flask pygal


    【解决方案1】:

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

    所以你得到:

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

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

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

    【讨论】:

      猜你喜欢
      • 2013-02-09
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 2012-03-01
      • 2014-06-21
      • 2021-10-16
      • 2019-09-12
      • 1970-01-01
      相关资源
      最近更新 更多