Jas*_*key 1 html javascript css highcharts
我需要为xAxis Label设置最大宽度,以便当它太长而其余字母(字符)将转到下一行.
我在设置标签步骤中读取了Highcharts x轴标签文本包装丢失,并且找到设置"width"对于英语单词(由空格分隔)正常工作.
但是当没有空地时,说"VeryLongLongLongWord"或"这是一个很长很长很的中文",那是行不通的.
我也尝试过设置wordWrap: break-word,仍然没用.
$(function () {
$('#container').highcharts({
chart: {
type: 'column',
},
xAxis: {
categories: ['This is a long Text', 'VeryLongLongLongWord', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec','?????????????'],
labels: {
style:{
width:'30px',// not work for text without empty space
wordWrap: 'break-word'//no use
},
step: 1
}
},
plotOptions: {
series: {
pointWidth: 30
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
});
Run Code Online (Sandbox Code Playgroud)
fidder:http://jsfiddle.net/uehbmzgx/
@ Sebastian的解决方案很好.
我找到了另一种解决方案,使用formatter来限制它的宽度:
labels: {
useHTML:true,//Set to true
style:{
width:'50px',
whiteSpace:'normal'//set to normal
},
step: 1,
formatter: function () {//use formatter to break word.
return '<div align="center" style="word-wrap: break-word;word-break: break-all;width:50px">' + this.value + '</div>';
}
},
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/uehbmzgx/5/