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