so I'm trying to display some vm performance data on javascript charts. It 
needs the information as a list, I have tried passing a json list from 
django and a django list like below in the javascript i ahve the one they 
tell me to use and the one im trying the one they tell me to use works 
obviously and i kept it there as reference to see how it needs to be input. 
How do I get the variables between django and javascript in an acceptable 
way?




         for stat in vm_stats:
             cpu_values.append(stat[4])
          cpu_json = simplejson.dumps(cpu_values)
          
          context = Context({'user.is_superuser':user.is_superuser, 
                            'customers':customers,
                            'vms': vms,
                            'vm_stats': vm_stats,
                            'customer_id': customer_id,
                            'cpu_json':cpu_json,
   
                            
                             })


<script src="{% static 'js/chart.js' %}"></script>
<script>
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
var lineChartData = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
label: "My First dataset",
fillColor : "rgba(220,220,220,0.2)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(220,220,220,1)",
data : [{{cpu_json}}]
},
{
label: "My Second dataset",
fillColor : "rgba(151,187,205,0.2)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(151,187,205,1)",
data : 
[randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
}
]

}

window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx).Line(lineChartData, {
responsive: true
});
}


</script>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ba87232e-783d-4b15-ba72-570026fdcb5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to