How can I get width parent element or default chart element when I define the chart for calculated x max in xAxis
?
This is my expected code:
xAxis: {
max: data.length < this.parent.width / 32 ? data.length - 1 : this.parent.width / 32,
min: 0,
categories: data,
labels: {
rotation: -40,
style: {
color: '#eb9123'
},
}
},
If you want to know what is the width of the div container where the chart belongs, then you can achieve it by chart.chartWidth
. Also, you can update the axis on load event .
chart: {
events: {
load: function () {
var width = this.chartWidth / 32,
dataLen = this.series[0].data.length,
max = dataLen < width ? dataLen - 1 : width;
console.log(max);
this.xAxis[0].update({
max: max
});
}
}
},
example: http://jsfiddle.net/91zbg0dx/
If you want to have that ability responsive, you have to do the same on redraw event .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.