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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more