abhiramrp
abhiramrp

Reputation: 129

Why is Plotly displaying empty space when displaying a graph through django data?

I am trying to print a pie graph using from Django but it is showing an empty space instead of printing the pie chart. I used the instructions from https://plotly.com/javascript/pie-charts/ but I am getting an error. How do I fix it?

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>

Upvotes: 2

Views: 761

Answers (1)

bas
bas

Reputation: 15432

The problem is that your values are all negative.

Non numeric or negative values are ignored in the pie chart sector calculations (source code), so no slices show up making the graph look empty.

Upvotes: 1

Related Questions