1var endpoint = 'api/'
2$.ajax({
3
4 method : "GET",
5 url : endpoint,
6
7 success: function(data){
8 new Chart(document.getElementById("line-chart"), {
9 type: 'line',
10 data: { labels : data.labels,
11 datasets : data.items
12 },
13 options : {
14 title : {
15 display : true,
16 text : data.title }
17 } } ); },
18
19 error: function(error_data){
20 console.log("error")
21 console.log(error_data) } } )
22
1from django.http import JsonResponse
2
3def get_data(request, *args, **kwargs):
4 title = 'World population per region (in millions)'
5 labels = [1500,1600,1700,1750,1800,1850,1900,1950,1999,2050]
6 items = [{ "data" : [86, 114, 106, 106, 107, 111, 133, 221, 783, 278],
7 "label" : "Africa",
8 "borderColor" : "#3e95cd",
9 "fill" : False},
10
11 { "data" : [282, 350, 411, 502, 635, 809, 947, 1402, 3700, 5267],
12 "label" : "Asia",
13 "borderColor" : "#8e5ea2",
14 "fill" : False}, ]
15
16 data = { "title" : title,
17 "labels": labels,
18 "items" : items }
19
20 return JsonResponse(data, safe=False)
21