Published
Edited
Nov 21, 2020
1 fork
Insert cell
md`# Calling API`
Insert cell
url = "https://mqtt.boomgrowfarms.com/test"
Insert cell
url2 = "https://mqtt.boomgrowfarms.com/getMsg"
Insert cell
md `Disable CORS in nginx with

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

Get json
response2 = await d3.json(url)

Slice and format for charts with .map

name : id
value : co2 values
`
Insert cell
d3 = require("d3@5")
Insert cell
response2 = await d3.json(url)
Insert cell
co2format = response2.rows.map(function(d) {
return {
name: d.id,
value: d.value
}
})
Insert cell
co2values = co2format.splice(0,20)
Insert cell
import {chart as barchart} with { co2values as data } from '@d3/bar-chart'
Insert cell
barchart
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more