【问题标题】:Why is Plotly displaying empty space when displaying a graph through django data?为什么通过 django 数据显示图表时 Plotly 显示空白?
【发布时间】:2022-01-11 04:25:53
【问题描述】:

我正在尝试使用 Django 打印饼图,但它显示的是空白区域,而不是打印饼图。我使用了来自https://plotly.com/javascript/pie-charts/ 的说明,但出现错误。我该如何解决?

views.py

labels = list(account_graph.keys()) # ['Food', 'Gas', 'Friends'] 
data = list(account_graph.values()) # [-6.09, -20.0, -7.0]

return render(request, "finances/account.html", {'labels': labels, 'data': data})

account.html

<div id='expenses'></div>

<script>

      var data = [{
        values: {{data|safe}},
        labels: {{labels|safe}},
        type: 'pie'
      }];

      var layout = {
        height: 400, 
        width: 500
      }

      Plotly.newPlot('expenses', data, layout);
</script>

【问题讨论】:

    标签: javascript django plotly


    【解决方案1】:

    问题是你的价值观都是负面的。

    在饼图扇区计算 (source code) 中会忽略非数字或负值,因此不会显示任何切片,从而使图表看起来是空的。

    【讨论】:

      猜你喜欢
      • 2016-06-07
      • 2015-04-14
      • 2012-03-29
      • 2020-07-27
      • 1970-01-01
      • 2016-10-15
      • 2020-08-13
      • 1970-01-01
      相关资源
      最近更新 更多