Published
Edited
Apr 3, 2019
Insert cell
Insert cell
Insert cell
twitterResponses = "https://gist.githubusercontent.com/cesandoval/ca0310352cc98742fc846e6a86a80c04/raw/0a591c6b7c4316235601b5a809df854f939418f2/twitter_response.json"
Insert cell
tweets = d3.json(twitterResponses) //parsed the json; statuses is an array, search_metadata is an object
Insert cell
Insert cell
statuses = tweets.statuses //each status is an object with its own properties/keys/values
Insert cell
searchMetadata = tweets.search_metadata
Insert cell
Insert cell
statuses[0]
Insert cell
Insert cell
text = statuses[0].text
Insert cell
textId = statuses[0].id
Insert cell
Insert cell
userId = statuses[0].user.id
Insert cell
userName = statuses[0].user.name
Insert cell
Insert cell
{
let emptyArray = []
for(let i in statuses){
let currStatus = statuses[i]
let tweetId = currStatus.id
emptyArray.push(tweetId) //add it to the emptyArray
}
return emptyArray
}
Insert cell
{
let texts = []
for (let i in statuses) {
let currentText = statuses[i].text
texts.push(currentText)
}
return texts
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
exData = [40,90,30,60,80];
Insert cell
{
let w = 160;
let h = 180;
const svg = d3.select(DOM.svg(w,h));
svg.selectAll("rect") //create empty rectangle
.data(exData) //pull the data into the svg
.enter() //bind data into the svg to bind d to i
.append("rect") //append to rectangle
.attr("x", (data,i) => (i*25+30))
//d becomes the placeholder for exData; loop through
//for each index in array, go thru i*25 + 30. First element = i = 0; 30, 55, 80, 105 are x places.

.attr("y",60)
.attr("width",20)
.attr("height", data => data)
.attr("fill", "steelblue");
return svg.node();
}

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