line chart using json django
from django.http import JsonResponse
def get_data(request, *args, **kwargs):
title = 'World population per region (in millions)'
labels = [1500,1600,1700,1750,1800,1850,1900,1950,1999,2050]
items = [{ "data" : [86, 114, 106, 106, 107, 111, 133, 221, 783, 278],
"label" : "Africa",
"borderColor" : "#3e95cd",
"fill" : False},
{ "data" : [282, 350, 411, 502, 635, 809, 947, 1402, 3700, 5267],
"label" : "Asia",
"borderColor" : "#8e5ea2",
"fill" : False}, ]
data = { "title" : title,
"labels": labels,
"items" : items }
return JsonResponse(data, safe=False)
var endpoint = 'api/'
$.ajax({
method : "GET",
url : endpoint,
success: function(data){
new Chart(document.getElementById("line-chart"), {
type: 'line',
data: { labels : data.labels,
datasets : data.items
},
options : {
title : {
display : true,
text : data.title }
} } ); },
error: function(error_data){
console.log("error")
console.log(error_data) } } )
Also in JavaScript:
- how to go to settings on next click in react native
- toast in react native
- how to get the value of textarea in react
- chart.js data from mysql vanila javscript
- java script hash
- javascript modal
- Node Js templates
- react native add two view
- react native backgrunde img
- $(getJson) returning error
- express delete image
- js multiply string
- how to store textbox data while typing for chrome extension
- ovelay text on image in react native
- js get url static without path from strin
- fetch data from external url nodejs
- component unmount useeffect
- share link in express js
- how to take an element out of an array in javascript
- '{ state: any; dispatch: React.Dispatch<{ type: string; payload: any; }>; }' is not assignable to type 'Store'
- download audio file javascript
- js remove escape characters from json
- javascript map function
- javascript remove last word from string