Created
March 17, 2017 07:44
-
-
Save hygull/97c54d4e29cba58e9f479bfcd2621262 to your computer and use it in GitHub Desktop.
To add dynamic anchor elements to draw dynamic google map & line chart created by hygull - https://repl.it/G0Gn/1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*To dynamically draw chart based on the result of call at http://filtron.pythonanywhere.com/api-view/lora-evk-sensors/, use the proper url, commented lines are also important*/ | |
| $.ajax({ | |
| url:"http://filtron.pythonanywhere.com/api-view/lora-evk-sensors/", | |
| //url:"http://127.0.0.1:8000/lora-evk-sensors/", | |
| dataType:"json", | |
| }).done(function(result){ | |
| console.log(result); | |
| var ctx = document.getElementById("myChart").getContext("2d"); | |
| labels = [] | |
| data_list = [] //array of objects | |
| door_status = [] | |
| gps_status = [] | |
| latitude = [] | |
| longitude = [] | |
| for (var i=0;i < result.length;i++) | |
| { | |
| door_status.push(result[i]["door_status"]) | |
| gps_status.push(result[i]["gps_status"]) | |
| latitude.push(result[i]["latitude"]) | |
| longitude.push(result[i]["longitude"]) | |
| /*Area to add links dynamically*/ | |
| var a = document.createElement("a"); | |
| var text = document.createTextNode("View Map"); | |
| a.appendChild(text); | |
| a.title = "map"; | |
| // a.href="/google_map/dynamic/12.9538477/-77/" | |
| a.href="/google_map/dynamic/"+result[i]["latitude"]+"/"+result[i]["longitude"]+"/" | |
| document.body.appendChild(a) | |
| /*Area to add links dynamically ended*/ | |
| } | |
| for (var i=0;i<result.length;i++){ | |
| // labels.push() | |
| data_list.push({label:result[i]["device_id"], | |
| data:[result[i]["door_status"], | |
| result[i]["gps_status"], | |
| result[i]["latitude"], | |
| result[i]["longitude"], | |
| ]}) | |
| } | |
| console.log("List of door status") | |
| console.log(door_status) | |
| console.log(gps_status) | |
| console.log(latitude) | |
| console.log(longitude) | |
| console.log("final data list \n",data_list) | |
| var myChart = new Chart(ctx,{ | |
| type:"line", | |
| data:{ | |
| // labels:["Door status","GPS status","Lattitude","Longitude","Movement status","dopen_freq", "rel_humidity","reporting_inter","switch1 status","switch2 status","temperature"], | |
| labels:["Door status","GPS status","Lattitude","Longitude"], | |
| // datasets:[ | |
| // { | |
| // label:"Device1", | |
| // data:[1,0,37.422,-120.4847] | |
| // }, | |
| // { | |
| // label:"Device2", | |
| // data:[0,1,34.4847,-122.147918] | |
| // } | |
| // ] | |
| datasets:data_list | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment