Ba Basi sic Data Visu sualization
Chaipo Chaiporn J n Jaik aikae aeo De Department of f Computer Engineering Kasetsart Unive versity
01219335 Data Acquisition and Integration
Revised 2020-11-04
Ba Basi sic Data Visu sualization 01219335 Data Acquisition and - - PowerPoint PPT Presentation
Ba Basi sic Data Visu sualization 01219335 Data Acquisition and Integration Chaipo Chaiporn J n Jaik aikae aeo De Department of f Computer Engineering Kasetsart Unive versity Revised 2020-11-04 Ou Outline Visualization design
Revised 2020-11-04
2
Survey & Questionnaires Survey & Questionnaires
IoT Devices IoT Devices
Survey & Questionnaires
Web API
raw files / web scraping
developers
Data Acquisition Devices
MQTT
Data Visualization
general public policy makers
4
5
https://paragraft.wordpress.com/2008/06/03/the-chart-junk-of-steve-jobs/
https://extremepresentation.typepad.com/blog/2006/09/choosing_a_good.html
7
visualization libraries, mostly written in JavaScript
HTTP web browser (client) web server
8
HTTP
web server web browser data image
png, pdf, svg, etc.
9
HTTP
web server web browser data
drawing csv, json, xml, etc. JavaScript code
10
11
12
java -jar openapi-generator-cli-4.3.1.jar generate \
python3.9 -m venv env . env/bin/activate # macOS and Linux env\Scripts\activate.bat # Windows pip install -r requirements.txt May type them all in one line without the \ character For Windows’ command prompt, use the ^ character instead of \ to continue on the second line
13
python app.py
14
15
16
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Average Monthly Rainfalls</title> <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> <body> <div id="chart" style="width:100%;height:75vh;"></div> <script> // Plotting script goes here // : </script> </body> </html>
Load Plotly Javascript library Create a div for the chart's placeholder
17
var resp = await fetch('http://localhost:3000/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: JSON.stringify({ query: ` { basin(basinId: 3) { name avgMonthlyRainfalls { amount month } } }` }) });
Fetch only Ping river's data (for now)
18
var json = await resp.json(); var table = json.data; var data = [{ x: table.basin.avgMonthlyRainfalls.map(row => row.month), y: table.basin.avgMonthlyRainfalls.map(row => row.amount), type: 'line', name: table.basin.name, }];
{ "data": { "basin": { "name": "Ping", "avgMonthlyRainfalls": [ { "amount": 7.31, "month": "Jan" }, { "amount": 8.46, "month": "Feb" }, { "amount": 25.01, "month": "Mar" }, { "amount": 55.14, "month": "Apr" }, { "amount": 177.9, "month": "May" }, { "amount": 130.2, "month": "Jun" }, { "amount": 127.25, "month": "Jul" }, { "amount": 167.59, "month": "Aug" }, { "amount": 209.1, "month": "Sep" }, { "amount": 153.51, "month": "Oct" }, { "amount": 36.7, "month": "Nov" }, { "amount": 8.76, "month": "Dec" } ] } } }
API's result Plotly's format
19
var layout = { title: 'Average Monthly Rainfalls for Ping River Basin', xaxis: { title: 'Month' }, yaxis: { title: 'Monthly Rainfall (mm)', range: [0,500] } }; var config = { responsive: true }; Plotly.newPlot("chart", data, layout, config); }
20
21
22
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Station Locations</title> <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> <script src="https://cdn.rawgit.com/mapbox/wellknown/master/wellknown.js"></script> <body> <div id="chart" style="width:100vw;height:100vh;"></div> <script> // Plotting script goes here // : </script> </body> </html>
Load wellknown.js for WKT à GeoJSON conversion
23
var resp = await fetch('http://localhost:3000/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: JSON.stringify({ query: ` { basin(basinId:3) { geom stations { name lat lon } } }` }) });
Fetch only Ping river's data (for now)
24
var json = await resp.json(); var table = json.data; var data = [ { type: "scattermapbox", text: table.basin.stations.map(row => row.name), lon: table.basin.stations.map(row => row.lon), lat: table.basin.stations.map(row => row.lat), marker: { color: "black", size: 10 }, }, ];
Utilize integrated Mapbox GL JS library
25
var layout = { dragmode: "zoom", showlegend: false, mapbox: { style: "open-street-map", center: { lat: 17.16, lon: 99.86 }, zoom: 6, layers: [ { source: { type: "Feature", geometry: wellknown.parse(table.basin.geom) }, type: "fill", color: "red", opacity: 0.2, }, ] }, margin: { r: 0, t: 0, b: 0, l: 0 } }; var config = { responsive: true }; Plotly.newPlot("chart", data, layout, config);
Convert WKT to GeoJSON
Use Mapbox with OpenStreetMap as the back-end tilemap (no access token required)
26
27
28
29