I have problem while passing a list of string from django views to javascript template. The quotation mark gets converted into hex and I cannot use it to plot graph using jpplot. I even tried replace method of javascript to replace the hex to convert to '.
The codes are as follows:
From views.py :
from django.shortcuts import render_to_response
def abc(request):
s1=[1, 5 , 8 , 3]
ticks=["a", "b", "c", "d"]
return render_to_response('abc.html', {'s1':s1, 'ticks':ticks})
From .html file (of template):
<script class="code" type="text/javascript">$(document).ready(function(){
$.jqplot.config.enablePlugins = true;
var s1 ={{ s1 }}
var ticks ={{ ticks }}
plot1 = $.jqplot('chart1', [s1], {
// Only animate if we're not using excanvas (not in IE 7 or IE 8)..
animate: !$.jqplot.use_excanvas,
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true }
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
}
},
highlighter: { show: false }
});
$('#chart1').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
$('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
}
);
});
</script>
when I view the source of the html file i get {{ ticks }} as
['a', 'b', 'c', 'd']
when I view the source of the html file i get {{ ticks }} as
['a', 'b', 'c', 'd']
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/mlgFT3rjmLQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment