Published
Edited
Oct 28, 2020
1 fork
1 star
Insert cell
Insert cell
d3 = require('d3-fetch')
Insert cell
convert = require('https://bundle.run/xml-js@1.6.11')
Insert cell
data = {
// let xml = await d3.text(
// 'https://swat-ds-cors-anywhere.herokuapp.com/http://advisory.mtanyct.info/LPUWebServices/CurrentLostProperty.aspx'
// );
let xml = await d3.text(
'https://bulbil.static.observableusercontent.com/files/88f40871d2e74ca34d2d084598353493520cf22bd7af66a7df01fa3f9f1fc996c29994e56785564e0aacbbd33673004745956facf64bcacf09d047166a4ef70f?response-content-disposition=attachment%3Bfilename*%3DUTF-8%27%27CurrentLostProperty.xml&Expires=1603972800000&Key-Pair-Id=APKAJCHFJLLLU4Y2WVSQ&Signature=UYhGzPBcpHnz2L7cg5xQAGtjtjaY~aDkz70ieOsUydTm9tlo3li5RtMXSuzav0Vb~UcNMIUFXtqDXM~XQ6EXyH0-CG~GPNWKs-iVLwJVCxgNIOi6jl3f4FfqNNJuru5Erx18reH-yEnEGDdQyiraXLWdMbU6mOe5bSJ209lcp~UtcrxFqOtymc6cV2gDCS9JGGNZWpZqHdAjryKzGLbhMay-iE4T~Kn3W9mfmYm1ccuZtYBhCOwp1VgguGfxk0c1drI-go7lACTSJqk7p61RAAR1913UJmc78cqT2qFtbBk~V1cgayX1hnTwU9j~UhNgdfuEBLsQwqSH7weBmpSwrQ__'
);

return convert.xml2js(xml);
}
Insert cell
Insert cell
categories = data.elements[0].elements.filter(function(d) {
console.log(d.name);
if (d.name == "Category") {
return d;
}
})
Insert cell
subcategories = {
let data = [];
categories.forEach(function(d, i) {
let currCategory = d.attributes.Category;

d.elements.forEach(function(d) {
let curr = d.attributes;
curr.Category = currCategory;
data.push(curr);
});
});

// return JSON.stringify(data);
return data;
}
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
vl
.markBar()
.data(subcategories)
.encode(
vl.x().fieldN('SubCategory'),
vl.y().fieldQ('count'),
vl.color().fieldN('Category')
)
.render()
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