Embedding matplotlib moving chart in django template | بلاگ

Embedding matplotlib moving chart in django template

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

Vote count: 0

I am new to python Django framework.

I have matplotlib moving or live chart, It should be embedded in django template. I checked many question relevant to this here but none of them is worked for me. Most of us suggested here is displaying as image, but problem is moving chart with default interface like zoom, drag everything to be integrated. i am struggling to solve . I used this code and got to know it will be displaying as image.

def simple(request):
import random
import django
import datetime

from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.dates import DateFormatter

fig = Figure()
ax = fig.add_subplot(111)
x = []
y = []
now = datetime.datetime.now()
delta = datetime.timedelta(days=1)
for i in range(10):
    x.append(now)
    now += delta
    y.append(random.randint(0, 1000))
ax.plot_date(x, y, '-')
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
canvas = FigureCanvas(fig)
response = django.http.HttpResponse(content_type='image/png')
canvas.print_png(response)
return response

I used this code for reference.

if this is not understandable please comment below, ill try to convey you clearly

can any one help me to get fixed this. Thanks in advance.

asked 46 secs ago
Mj_7

...
نویسنده : استخدام کار بازدید : 7 تاريخ : دوشنبه 23 بهمن 1396 ساعت: 20:08