Overlapping bars on mobile
Two series over twelve months whose bars move closer together and labels shorten on small screens.
src/main.ts
import 'chartist/styles.css';
import {
barChart,
type BarChartPresetOptions,
type PresetResponsiveOptions
} from 'chartist';
const data = {
labels: [
'Jan',
'Feb',
'Mar',
'Apr',
'Mai',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
],
series: [
[5, 4, 3, 7, 5, 10, 3, 4, 8, 10, 6, 8],
[3, 2, 9, 5, 4, 6, 4, 6, 7, 8, 7, 4]
]
};
const options = {
seriesBarDistance: 15
};
const responsiveOptions: PresetResponsiveOptions<BarChartPresetOptions> = [
[
'screen and (min-width: 641px) and (max-width: 1024px)',
{
seriesBarDistance: 10,
axisX: {
labelInterpolationFnc: value => value
}
}
],
[
'screen and (max-width: 640px)',
{
seriesBarDistance: 5,
axisX: {
labelInterpolationFnc: value => String(value)[0]
}
}
]
];
barChart('#chart', data, options, responsiveOptions);import 'chartist/styles.css';
import {
BarChart,
type BarChartOptions,
type ResponsiveOptions
} from 'chartist';
const data = {
labels: [
'Jan',
'Feb',
'Mar',
'Apr',
'Mai',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
],
series: [
[5, 4, 3, 7, 5, 10, 3, 4, 8, 10, 6, 8],
[3, 2, 9, 5, 4, 6, 4, 6, 7, 8, 7, 4]
]
};
const options = {
seriesBarDistance: 15
};
const responsiveOptions: ResponsiveOptions<BarChartOptions> = [
[
'screen and (min-width: 641px) and (max-width: 1024px)',
{
seriesBarDistance: 10,
axisX: {
labelInterpolationFnc: value => value
}
}
],
[
'screen and (max-width: 640px)',
{
seriesBarDistance: 5,
axisX: {
labelInterpolationFnc: value => String(value)[0]
}
}
]
];
new BarChart('#chart', data, options, responsiveOptions); 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.