2

I am trying to display a multi dimensional bar chart using mpld3 and django framework.

when I run the following code, it produces error

Object of type 'ndarray' is not JSON serializable

at fig_to_html() function line

here I attached my working copy:

view.py

def home(request):
    get_barchart = barchart()

    return render(request,"home.html",{
        "barchart":get_barchart
    }
)

def barchart():
    fig = plt.figure()
    plt.scatter([1, 10], [5, 9])
    html_graph = mpld3.fig_to_html(fig)

    return html_graph

html template:

<html>
    <head>
        <title>Chart Example</title>
    </head>

    <body>
        <h3>Chart Example</h3>
        <div>
            {{ barchart|safe }}
        </div>
    </body>
</html>
Tms91
  • 3,456
  • 6
  • 40
  • 74
ArunKumar
  • 179
  • 1
  • 1
  • 11

0 Answers0