Extreme responsive configuration
Five series per quarter that switch between stacked, horizontal and grouped bars as the screen grows.
src/main.ts
import 'chartist/styles.css';
import { barChart, noop } from 'chartist';
barChart(
'#chart',
{
labels: ['Quarter 1', 'Quarter 2', 'Quarter 3', 'Quarter 4'],
series: [
[5, 4, 3, 7],
[3, 2, 9, 5],
[1, 5, 8, 4],
[2, 3, 4, 6],
[4, 1, 2, 1]
]
},
{
// Default mobile configuration
stackBars: true,
axisX: {
labelInterpolationFnc: value =>
String(value)
.split(/\s+/)
.map(word => word[0])
.join('')
},
axisY: {
offset: 20
}
},
[
// Options override for media > 400px
[
'screen and (min-width: 400px)',
{
reverseData: true,
horizontalBars: true,
axisX: {
labelInterpolationFnc: noop
},
axisY: {
offset: 60
}
}
],
// Options override for media > 800px
[
'screen and (min-width: 800px)',
{
stackBars: false,
seriesBarDistance: 10
}
],
// Options override for media > 1000px
[
'screen and (min-width: 1000px)',
{
reverseData: false,
horizontalBars: false,
seriesBarDistance: 15
}
]
]
);import 'chartist/styles.css';
import { BarChart, noop } from 'chartist';
new BarChart(
'#chart',
{
labels: ['Quarter 1', 'Quarter 2', 'Quarter 3', 'Quarter 4'],
series: [
[5, 4, 3, 7],
[3, 2, 9, 5],
[1, 5, 8, 4],
[2, 3, 4, 6],
[4, 1, 2, 1]
]
},
{
// Default mobile configuration
stackBars: true,
axisX: {
labelInterpolationFnc: value =>
String(value)
.split(/\s+/)
.map(word => word[0])
.join('')
},
axisY: {
offset: 20
}
},
[
// Options override for media > 400px
[
'screen and (min-width: 400px)',
{
reverseData: true,
horizontalBars: true,
axisX: {
labelInterpolationFnc: noop
},
axisY: {
offset: 60
}
}
],
// Options override for media > 800px
[
'screen and (min-width: 800px)',
{
stackBars: false,
seriesBarDistance: 10
}
],
// Options override for media > 1000px
[
'screen and (min-width: 1000px)',
{
reverseData: false,
horizontalBars: false,
seriesBarDistance: 15
}
]
]
); 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.