Published
Edited
Sep 8, 2020
Insert cell
md`# Stacked Multi Chart`
Insert cell
viewof numOfSeries = html`<input type="range" min="1" max="200" step="1" value="10">`
Insert cell
viewof xAxisCount = html`<input type="range" min="1" max="200" step="1" value="10">`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function addLine(selection, update) {
selection = update ? d3.select('#lines') : selection.append('g');
selection
// .append("g")
.attr('id', 'lines')
.selectAll("path")
.data(data.byTypes.stack.data.line)
.join("path")
.style("mix-blend-mode", "multiply")
.attr('fill-opacity', 0.5)
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr('stroke', d => color(d.key.name))
.attr("fill", 'none')
.attr("d", line)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
xAxisExtent = width - margin.left - margin.right
Insert cell
Insert cell
{
document.addEventListener('update', function (e) {

const domain = [0 ,d3.max(
[
d3.max(data.byTypes.stack.data.line, d => d3.max(d, d => d[1])),
d3.max(data.byTypes.stack.data.area, d => d3.max(d, d => d[1])),
d3.max(data.byTypes.stack.data.bar, d => d3.max(d, d => d[1])),
],
d => d
)]
chart.update(domain);
}, false);
}
Insert cell
unselectedColor = '#ddd'
Insert cell
Insert cell
function initStackView(category, byTypes) {
const view = {
line : [],
bar: [],
area : []
};
byTypes.stack.view = view;
byTypes.lines.map(d => d.display ? view.line.push(d) : null);
byTypes.areas.map(d => d.display ? view.area.push(d) : null);
byTypes.bars.map(d => d.display ? view.bar.push(d) : null);

byTypes.stack.data.line = stackSeries(view.line , category)
byTypes.stack.data.bar = stackSeries(view.bar , category)
byTypes.stack.data.area = stackSeries(view.area , category)

}
Insert cell
d3 = require("d3@6")
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