Published
Edited
1 fork
Insert cell
Insert cell
dataset = d3.csv("https://gist.githubusercontent.com/emanueles/d8df8d875edda71aa2e2365fae2ce225/raw/1e949d3da02ed6caa21fe3a7a12a4e5a611a4bab/stocks.csv").then(function(data){
// formatando nossos dados
let parseDate = d3.timeParse("%Y/%m/%d")
data.forEach(function(d,i){
d.date = parseDate(d.date)
d.google = +d.google
d.facebook = +d.facebook
})
return data
})
Insert cell
facts = crossfilter(dataset)
Insert cell
dateDim = facts.dimension( d => d.date)
Insert cell
googleDim = facts.dimension( d => d.google)
Insert cell
topTenGoogle = googleDim.top(10)
Insert cell
bottomTenGoogle = googleDim.bottom(10)
Insert cell
googleByDayGroup = dateDim.group().reduceSum(d => d.google)
Insert cell
fbDim = facts.dimension(d => d.facebook)
Insert cell
fbByDayGroup = dateDim.group().reduceSum(d => d.facebook)
Insert cell
fbPercFirstDay = dateDim.group().reduceSum(d => 100*(d.facebook/fbByDayGroup.all(1)[0].value-1))
Insert cell
googlePercFirstDay = dateDim.group().reduceSum(d => 100*(d.google/googleByDayGroup.all(1)[0].value-1))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
datasetMovies = d3.json('https://raw.githubusercontent.com/emanueles/datavis-course/master/assets/files/observable/movies.json').then(function(data){
// formatando nossos dados
data.forEach(function(d,i){
d.film = d['Film']
d.year = +d.Year
d.genre = d['Genre']
d.worldwideGross = +d.Worldwide_Gross_M
d.budget = +d.Budget_M
})
return data
})
Insert cell
facts2 = crossfilter(datasetMovies)
Insert cell
filmDim = facts2.dimension( d => d.film)
Insert cell
yearDim = facts2.dimension( d => d.year)
Insert cell
genreDim = facts2.dimension( d => d.genre)
Insert cell
worldwideGrossDim = facts2.dimension( d => d.worldwideGross)
Insert cell
budgetDim = facts2.dimension( d => d.budget)
Insert cell
worldwideGrossByYearGroup = yearDim.group().reduceSum(d => d.worldwideGross)
Insert cell
worldwideGrossByGenreGroup = genreDim.group().reduceSum(d => d.worldwideGross)
Insert cell
by_year = {
let view = md`${container('barchart1','Bilheteria/ano')}`
let barChart = dc.barChart(view.querySelector("#barchart1"))
barChart.width(500)
.height(400)
.dimension(yearDim)
.margins({top: 40, right: 40, bottom: 40, left: 40})
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.brushOn(true)
.gap(30)
.group(worldwideGrossByYearGroup, 'Bilheteria/Ano')
dc.barChart
barChart.render()
return view
}
Insert cell
by_genre = {
let view = md`${container('barchart2','Bilheteria/gênero')}`
let barChart = dc.barChart(view.querySelector("#barchart2"))
barChart.width(500)
.height(400)
.margins({top: 40, right: 40, bottom: 40, left: 40})
.dimension(genreDim)
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.brushOn(true)
.gap(10)
.group(worldwideGrossByGenreGroup)
barChart.render()
return view
}
Insert cell
Insert cell
dc = require("dc")
Insert cell
crossfilter = require("crossfilter2")
Insert cell
d3 = require("d3")
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