Public
Edited
Mar 6, 2023
Insert cell
Insert cell
barchart = bars.plot({
y: { domain: [-30, 100] },
color: { scheme: "Reds", domain: [-30, 100] },
marks:[
Plot.axisX({label: null, lineWidth: 4, marginBottom: 60,textsize:4}),
Plot.axisY({label: "↑ Mabadiliko toka Wastani wa bei za 2015 (%)"})
//,
//Plot.text(gdata, { x: ['Chakula na Vinywaji Bila Pombe','Pombe na Sigara','Nguo na Viatu','Nishati na Nyumba','Vifaa na Ukarabati wa Nyumba','Afya','Usafiri','Tehama','Michezo na Utamaduni','Elimu','Malazi','Bima','Bidhaa nyingine'],text: d => (d).toFixed(1), dy: -5 })
]
})
Insert cell
//bars = barY(data, { x: (d, i) => i, fill: (d) => d })
bars = barX(data, { x: ['Chakula na Vinywaji Bila Pombe','Pombe na Sigara','Nguo na Viatu','Nishati na Nyumba','Vifaa na Ukarabati wa Nyumba','Afya','Usafiri','Tehama','Michezo na Utamaduni','Elimu','Malazi','Bima','Bidhaa nyingine'], fill: (d) => d})
Insert cell
data = Array.from({ length: 13 }, d3.randomInt(0, 0))
Insert cell
Insert cell
gdata = {
//barchart;
//do {
for (let i = 0; i < 84; i++){
//const updated = data.map(d3.randomInt(-40, 40));
const updated = g[i]
yield updated;
await bars
.transition({ Y: updated, F: updated }, { delay: 150, duration: 300 })
.end();
}
//} while (true);
}
Insert cell
barX = function (data, options) {
const B = Plot.barY(data, options);
const { render } = B;
const G = [];
let c;
let that;

B.render = function (I, scales, channels, dimensions) {
c = { scales, dimensions };
that = this;

const g = render.apply(this, arguments);
G.push(g);

return g;
};

B.transition = ({ Y, F }, { delay = 500, duration = 1000 } = {}) => {
const y1 = Array.from(Y, () => c.scales.y(0));
const y2 = Array.from(Y, c.scales.y);

// here's how bars dimensions are controlled within Plot.BarY:
const y = that._y(c.scales, { y1, y2 }, c.dimensions);
const height = that._height(c.scales, { y1, y2 }, c.dimensions);

return d3
.selectAll(G)
.selectAll("rect")
.transition()
.delay(delay)
.duration(duration)
.attr("height", height)
.attr("fill", (i) => c.scales.color(F[i]))
.attr("y", y);
};

return B;
}
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