JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.highcharts.com/js/highcharts.js"></script>
<strong>Question:</strong> Can we adjust the line-height of axis labels in Highcharts when using CSS styled mode?
<div id="container"></div>
<p><strong>Using CSS styled branch:</strong> http://code.highcharts.com/js/highcharts.js</p>
<p><strong>With CSS:</strong> http://code.highcharts.com/css/highcharts.css</p>
SCSS
@import 'https://code.highcharts.com/css/highcharts.css';
body {
max-width: 640px;
margin: 2em auto;
text-align: center;
font-family: courier;
* {
font-family: courier;
}
}
#container {
min-width: 310px;
max-width: 500px;
height: 200px;
margin: 0 auto
}
.highcharts-xaxis-labels {
font-size: 15px;
// line-height: 0.5 !important; // Has no effect on line height
// text-overflow: none; // has no effect on automatic ellipsizing
text:nth-child(odd){ fill: blue; }
text:nth-child(even){ fill: red; }
}
JavaScript
var H = Highcharts;
H.wrap(H.Tick.prototype, 'addLabel', function (p) {
p.call(this);
const label = this.label;
const labelOptions = this.axis.options.labels;
if (label) {
label.css({
lineHeight: labelOptions.style.lineHeight
})
}
})
Highcharts.chart('container', {
chart: { type: 'bar' },
title: { text: null },
legend: { enabled: false},
credits: { enabled: false },
xAxis: {
labels: {
style: {
textOverflow: 'none', // To disable automatic ellipsizing, per https://github.com/highcharts/highcharts/issues/3941
// lineHeight: '0.5' // Has no effect
lineHeight: 12
}
},
categories: [
'Sweden',
'Federal Democratic Republic of Ethiopia',
'Finland',
'United Kingdom of Great Britain and Northern Ireland',
'Oceania'],
title: {
text: null
}
},
yAxis: {
visible: false,
labels: {
overflow: 'justify'
}
},
series: [{
name: 'Year 1800',
data: [107, 313, 635, 203, 262]
}]
});