solved
date_values= json.dumps(list(date_values), cls=DjangoJSONEncoder)

<script>
var date_values = {{ date_values|safe }};
var lineChartData = {
labels : date_values,
datasets : [
{
label: "CPU Usage in MHZ",
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_values}}
}
]

}

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

</script>



On Tuesday, July 29, 2014 9:47:40 AM UTC-6, G Z wrote:
>
> the values will show how, but i ran into another problem while trying to 
> input the labels, labels need to be strings so I input them as an array 
> such as the following: ["2014-07-28 14:24:11", "2014-07-28 14:24:11"] I 
> saved it as a simple json in django and pass it to the webbrowser and then 
> conver the json to a javascript value and pass that as the labels. Normally 
> labels is ['sdfsdf','sdfsfs'] which is exactly how I pass mine Ive passed 
> with "" and '' it doesn't matter. I'm trying to use the datetimes as the 
> graph labels.
>
> <script src="{% static 'js/chart.js' %}"></script>
> <script> 
> var dates = JSON.parse("{{ date_values }}");
> var lineChartData = {
> labels : [dates],
> datasets : [
> {
> label: "CPU Usage in MHZ",
> 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_values}}
> }
> ]
>
> }
>
> 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/55111b32-dafe-4923-baf8-0d13ad42940a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to