Published
Edited
Feb 10, 2020
2 forks
1 star
Insert cell
md`# Stacked Area Chart`
Insert cell
html`<div id='container' style="height:400px;position:relative;"></div>`
Insert cell
picasso = require("picasso.js")
Insert cell
data = {
var arr = [['Year', 'Month', 'Sales']];

var months = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'June',
'July',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
];
for (var i = 0; i < 6; i++) {
for (var m = 0; m < months.length; m++) {
arr.push([
String(2010 + i),
months[m],
parseFloat((Math.random() * 10000).toFixed(0)),
parseFloat((Math.random() * 100).toFixed(0))
]);
}
}
return [
{
type: 'matrix',
data: arr
}
];
}
Insert cell
picasso.chart({
element: document.querySelector('#container'),
data,
settings: {
collections: [
{
key: 'stacked',
data: {
extract: {
field: 'Month',
props: {
line: { field: 'Year' },
end: { field: 'Sales' }
}
},
stack: {
stackKey: d => d.value,
value: d => d.end.value
}
}
}
],
scales: {
y: {
data: {
collection: {
key: 'stacked'
}
},
invert: true,
expand: 0.2,
min: 0
},
t: { data: { extract: { field: 'Month' } } },
color: { data: { extract: { field: 'Year' } }, type: 'color' }
},
components: [
{
type: 'axis',
dock: 'left',
scale: 'y'
},
{
type: 'axis',
dock: 'bottom',
scale: 't'
},
{
key: 'lines',
type: 'line',
data: {
collection: 'stacked'
},
settings: {
coordinates: {
major: { scale: 't' },
minor0: { scale: 'y', ref: 'start' },
minor: { scale: 'y', ref: 'end' },
layerId: { ref: 'line' }
},
layers: {
curve: 'monotone',
line: {
show: true
},
area: {
fill: { scale: 'color', ref: 'line' }
}
}
}
}
]
}
})
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