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>