Tuesday, June 30, 2020

How to display a line graph in Django?

Hi all, 

I have wrote a python program to display the line graph as follows: 

import matplotlib.pyplot as plt

x
= [1,2,3]
y
= [2,4,1]
 

plt
.plot(x, y)
 

plt
.xlabel('x - axis')
plt
.ylabel('y - axis')
 

plt
.title('My first graph!')
 
plt
.show()


Now I need to display the same via Django. So I think I need to write the above code in the view and then redirect the same to the html template file. Am I right?

In that case, how to send the request objects related to the line chart to the template?

Normally, we send in the following format:

def view1(request)


 
return render(request, 'display_report.html', { 'var1': "abc", ...
 
... })

So if we are trying to display the line graph generated by the above code, how to do so ? 

Please share your inputs. 

Thanks. 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/827e0d0c-6bbb-4511-af73-9fa379df699do%40googlegroups.com.

No comments:

Post a Comment