I have stackLabels that I have added in the x- axis, I have added a formatter function that will truncate the x-axis labels in order to fit into the chart size: something like this:
https://jsfiddle.net/jqdf7nap/
however as the data and the width of the series column chart changes I would also like to change the truncated number of chars on the string.currently I have this:
stackLabels: {
enabled: true,
verticalAlign: 'bottom',
//y:160,
style: {
fontWeight: 'bold',
color: 'gray'
},
formatter: function () {
let label = this.stack || '';
let truncatedLabel = label.length <= 3
? label : `${label.substring(0, 3)}...`;
return `<span>${truncatedLabel}</span>`;
},
}
the above will always truncate the string regardless of the size of the series column.ex if a wider series is available it'll still truncate to 3. like this
https://jsfiddle.net/ka9uhx10/
Instead I would like to show this https://jsfiddle.net/f2bv35gy/
is there any way to dynamically pass the substring char number to the string based on the chart point width?
Try to use the
dataLabels
instead thestackLabels
and use the below config:Demo: https://jsfiddle.net/BlackLabel/47e3msuk/
API: https://api.highcharts.com/class-reference/Highcharts.CSSObject#textOverflow
API: https://api.highcharts.com/highcharts/series.line.dataLabels.overflow
API: https://api.highcharts.com/highcharts/chart.events.render