{
const colors = {
domain: ['IllegalDumping', 'BuildingMaintenance', 'Electrical', 'StreetSweeping', 'Graffiti',
'RoadRepair', 'Drainage', 'StreetLights', 'VegetationControl', 'Survey'],
range: ['#8B0000', '#006400', '#1E90FF', '#FFA500', '#800080', '#FFFF00', '#FF6347',
'#008000', '#FF69B4', '#808080']}
const shapes = {
domain: ['IllegalDumping', 'BuildingMaintenance', 'Electrical', 'StreetSweeping', 'Graffiti',
'RoadRepair', 'Drainage', 'StreetLights', 'VegetationControl', 'Survey'],
range: ['circle', 'diamond', 'square', 'triangle', 'triangle', 'circle', 'diamond', 'square',
'triangle', 'triangle']}
const line = vl.markLine({strokeWidth:3, opacity: 0.5, interpolate: 'monotone'})
.data(stats)
.encode(
vl.x().fieldO('Year')
.axis({labelAngle: 0}),
vl.y().fieldQ('NumRequests')
.title("Number of Requests"),
vl.color().fieldN('ProblemType')
.scale(colors)
.legend({orient: 'top-left'}));
const points = vl.markPoint({size:100, filled:true})
.data(stats)
.encode(
vl.x().fieldO('Year'),
vl.y().fieldQ('NumRequests').title("Number of Requests"),
vl.color().fieldN('ProblemType').scale(colors),
vl.shape().fieldN('ProblemType').scale(shapes).legend(null));
const linegraph = vl.layer(line, points)
.width(500)
.height(1000)
.title({text: 'By Year', anchor: 'middle', font: 'Tahoma', fontSize: 15});;
const bars = vl.markBar()
.encode(
vl.x().fieldQ('NumRequests'),
vl.y().fieldO('Year').title(null),
vl.color().fieldQ('Year').scale({scheme:'greys'}).legend(null)
);
const text = vl.markText({type: 'text', align: 'left', baseline: 'middle', dx: 3})
.encode(
vl.text().fieldQ('NumRequests'),
vl.x().fieldQ('NumRequests'),
vl.y().fieldO('Year'));
const bartext = vl.layer(bars, text)
.facet({row: {field: 'ProblemType',
header: {title: null, labelAngle:360, labelAlign: 'left', labelFont: 'Tahoma',
labelFontStyle: 'bold', labelFontSize: 12},
sort: ['IllegalDumping', 'BuildingMaintenance', 'Electrical', 'StreetSweeping', 'Graffiti',
'RoadRepair', 'Drainage', 'StreetLights', 'VegetationControl', 'Survey']}})
.data(stats)
.title({
text: "By Problem Type",
fontSize: 15,
font: "Tahoma",
anchor: "middle"});
return vl.hconcat(linegraph, bartext).title({
text: 'City of Springfield Service Request Statistics (2009-2012)',
anchor: 'middle',
font: 'Tahoma',
fontSize: 20
}).render();
}