Stacked bar chart
Three series stacked per quarter, with a plugin that widens every bar.
src/main.ts
import 'chartist/styles.css';
import './style.css';
import { barChart } from 'chartist';
barChart(
'#chart',
{
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
series: [
[800000, 1200000, 1400000, 1300000],
[200000, 400000, 500000, 300000],
[100000, 200000, 400000, 600000]
]
},
{
stackBars: true,
axisY: {
labelInterpolationFnc: value => +value / 1000 + 'k'
}
}
);import 'chartist/styles.css';
import { BarChart } from 'chartist';
import { compat } from 'chartist/compat';
new BarChart(
'#chart',
{
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
series: [
[800000, 1200000, 1400000, 1300000],
[200000, 400000, 500000, 300000],
[100000, 200000, 400000, 600000]
]
},
{
// 1.x draw events come from the compat plugin in v2.
plugins: [compat],
stackBars: true,
axisY: {
labelInterpolationFnc: value => +value / 1000 + 'k'
}
}
).on('draw', data => {
if (data.type === 'bar') {
data.element.attr({
style: 'stroke-width: 30px'
});
}
}); Live
Open in the playgroundView as MarkdownSwitch to 1.x above the code to see the same chart written with the Chartist 1.x classes.