该案例是基于vue2.0脚手架,使用了elementUI、eCharts、screenfull插件
自适应echarts图表
第一,自适应的echarts图表,要配合着能够自适应的盒子来使用,首先就是盒子要能够跟随屏幕大小改变而改变,比如我们使用弹性盒子就可以实现。
第二,要想实现自适应的echarts图表,就是当窗口发生改变时,echarts图表的尺寸重新定义一下,使用resize的方法就可以实现。
总体布局
<template>
<div class="aboutPage">
<div class="chartBoxWrap" ref="chartBox">
<div id="chartBox"></div>
</div>
</div>
</template>
<style lang="scss" scoped>
.chartBoxWrap {
display: flex;
height: 600px;
#chartBox {
flex: 1;
background-color: #f0faf0;
}
}
</style>
创建echarts图表的方法
initChart(e){
let myChart = echarts.init(document.getElementById("chartBox"))
myChart.setOption({
title:{
text:"自适应图表"
},
legend:{
show:true,
icon:'circle'
},
xAxis:{
type:'category',
name:"月份",
data:e.xData
}