Published
Edited
Sep 12, 2021
Insert cell
Insert cell
vegalite = require("vega-embed@6")
Insert cell
Insert cell
dataset = FileAttachment("KAIST_300L.csv").csv({typed: true})
Insert cell
Insert cell
Insert cell
{
dataset.forEach(function(d)
{
if (d.acc_X == null || d.acc_Y == null || d.acc_Z == null) d.mag = null;
else d.mag = Math.sqrt(Math.pow(d.acc_Y,2) + Math.pow(d.acc_X,2) + Math.pow(d.acc_Z,2));
})
}
Insert cell
Insert cell
vegalite(
{
"data": {
"values": dataset,
},
"transform": [{"calculate": "month(datum.timestamp)", "as": "time"}],
"vconcat": [
{
"width": width-50,
"mark": {"type": "line"},
"encoding": {
"x": {
"timeUnit": "yearmonthdatehoursminutessecondsmilliseconds", //discretize times in Vega-Lite, indicates chronological time sensitive to year, month, date, hours, minutes, seconds and milliseconds
"field": "timestamp",
"type": "temporal",
"axis": {
"format": "%H:%M:%S", //format for displaying the axis labels. More on time formats: https://github.com/d3/d3-time-format#locale_format
"title": "May 04 2019",
"titleX": 30, //Shifts the title, to the right from the leftmost part
"titlePadding": 10,
},
"bin": {"binned": true, "extent": {"param": "brush"}} //discretizes into a set of bins and the extent of graph is determined the brush parameters
},
"y": { "field": "mag", "type": "quantitative", "title": "Magnitude of Acceleration→"}
}
},{
"width": width-50,
"height": 50,
"params": [{
"name": "brush",
"select": {"type": "interval", "encodings": ["x"]} //brushes based on x-encodings
}],
"mark": "line",
"encoding": {
"x": {
"timeUnit": "yearmonthdatehoursminutes",
"field": "timestamp",
"type": "temporal",
"axis": {
"grid": false,
"format": "%H:%M",
"title": "Time (Hours:Minutes:Seconds)→",
},
},
"y": {"field": "mag", "type": "quantitative", "title": "Mag→"}
}
}]
}
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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