1

I want to plot agraph using plotly.js library and the inputs to the graph is taken from the user through an html form.

I have created a html form to read X and Y values for the plot. In the views.py, i accessed the form data using request.POST.get and then added to a list x[],y[].

from django.shortcuts import render
x=[]
y=[]
def index(request):
    return render(request,'home.html')

def inputplot(request):
    if(request.method=="POST"):
       xvalue=request.POST.get('xvalue')
       yvalue=request.POST.get('yvalue')
       x.append(xvalue)
       y.append(yvalue)
       print x
       print y
       return render(request,'inputplot.html')
       del x[:]
       del y[:]
       return render(request,'inputplot.html')
def plot(request):
       `return render(request,'plot.html',{'x':x,'y':y})

I want the lists in plot.html but when i append data to the list it automatically add some characters. For example i input a number 12 for x value, but this number appears in the list as [u'12'].

Why this happened?

pls give me a solution or show me another method to read user data and plot the values.??? Help me

vishnu m c
  • 841
  • 1
  • 7
  • 21

1 Answers1

0

The data from your request.POST is a string here. The [u'12'] is telling you that it's a unicode string., which is why it's not plotting correctly.

Assuming they're all integers, you need something along the lines of: xvalue=int(request.POST.get('xvalue'))

Substitute with Decimal, if appropriate.

Community
  • 1
  • 1
Withnail
  • 3,128
  • 2
  • 30
  • 47