Stuck on python list to json object to jquery data chart -


i'm having trouble populating data chart on website. here data looked before in query:

var data2 = [             [gd(2012, 1, 1), 7], [gd(2012, 1, 2), 6], [gd(2012, 1, 3), 4], [gd(2012, 1, 4), 8],             [gd(2012, 1, 5), 9], [gd(2012, 1, 6), 7], [gd(2012, 1, 7), 5], [gd(2012, 1, 8), 4],             [gd(2012, 1, 9), 7], [gd(2012, 1, 10), 8], [gd(2012, 1, 11), 9], [gd(2012, 1, 12), 6],             [gd(2012, 1, 13), 4], [gd(2012, 1, 14), 5], [gd(2012, 1, 15), 11], [gd(2012, 1, 16), 8],             [gd(2012, 1, 17), 8], [gd(2012, 1, 18), 11], [gd(2012, 1, 19), 11], [gd(2012, 1, 20), 6],             [gd(2012, 1, 21), 6], [gd(2012, 1, 22), 8], [gd(2012, 1, 23), 11], [gd(2012, 1, 24), 13],             [gd(2012, 1, 25), 7], [gd(2012, 1, 26), 9], [gd(2012, 1, 27), 9], [gd(2012, 1, 28), 8],             [gd(2012, 1, 29), 5], [gd(2012, 1, 30), 8], [gd(2012, 1, 31), 25]         ]; 

in view have:

return httpresponse(json.dumps({'data': data}), content_type="application/json", status=200) 

the print before return is:

data: [[1505175303.4467661, 1], [1505175318.294838, 1], [1505175332.872905, 1], [1505175348.181136, 1]] 

however in alert(response.data) get:

1505175303.4467661, 1, 1505175318.294838, 1, 1505175332.872905, 1, 1505175348.181136, 

why converting array string or whatever is?

i'm doing through ajax call if changes anything?

sincerely,

denis angell

edit:

here gb function did before:

function gd(year, month, day) {             return new date(year, month - 1, day).gettime();         } 

alert(response.data) nothing try , format data display, calls tostring() on object given it, returns rudimentary string. although structure lost in presentation, underlying object remain intact.

instead of alert(response.data) try console.log(response.data), or alert(response.data[0][0]) convince data structure remains. or might iterate on returned object. try in javascript console:

data = [[1505175303.4467661, 1], [1505175318.294838, 1], [1505175332.872905, 1], [1505175348.181136, 1]];  alert(data); alert(data[0]); alert(data[0][0]); console.log(data);  data.foreach(function(element) {         alert(element[0] + ': ' + element[1]);     }); 

the first alert() should show apparent loss of structure, however, subsequent calls should show arrays still present.


also since you're using django, think, rather use httpresponse, use jsonresponse:

from django.http import jsonresponse  return jsonresponse({'data': data}) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -