# 优化x-axis 显示

This commit is contained in:
xianfuxing 2018-09-28 16:27:07 +08:00
parent 08ca34945d
commit 2cc2c2aa6a
1 changed files with 32 additions and 2 deletions

View File

@ -34,10 +34,16 @@ export default {
},
data() {
return {
chart: null
chart: null,
rotate: 0,
screenWidth: document.body.clientWidth
}
},
mounted() {
window.screenWidth = document.body.clientWidth
if (window.screenWidth <= 400) {
this.rotate = 30
}
this.initChart()
if (this.autoResize) {
this.__resizeHanlder = debounce(() => {
@ -51,6 +57,19 @@ export default {
//
const sidebarElm = document.getElementsByClassName('sidebar-container')[0]
sidebarElm.addEventListener('transitionend', this.__resizeHanlder)
//
const that = this
window.onresize = () => {
return (() => {
window.screenWidth = document.body.clientWidth
that.screenWidth = window.screenWidth
console.log(window.screenWidth)
if (window.screenWidth <= 400) {
this.rotate = 30
}
})()
}
},
beforeDestroy() {
if (!this.chart) {
@ -78,6 +97,16 @@ export default {
console.log(val)
this.chart.resize()
}
},
screenWidth(val) {
this.screenWidth = val
if (val <= 400) {
this.rotate = 30
this.setOptions(this.chartData)
} else {
this.rotate = 0
this.setOptions(this.chartData)
}
}
},
methods: {
@ -88,7 +117,8 @@ export default {
data: xAxis,
boundaryGap: false,
axisLabel: {
interval: 0
interval: 0,
rotate: this.rotate
},
axisTick: {
show: false