需求:
1.同一个滚动条 同时控制上下两个柱状图;
2.同一个vue页面多次渲染echarts图表的优化,组件封装;
3.数据量大的话默认显示最新的6条数据;
1.父组件(dashboard.vue):
<template>
<div class="dashboard">
<sbar-line></sbar-line>
</div>
</template>
<script>
import SbarLine from "./echart"
export default {
data(){
return{
}
},
components:{
SbarLine
},
methods:{},
mounted() {}
}
</script>
<style>
.dashboard{
width: 70%;
margin: 20px auto;
height: 500px;
}
</style>
2.子组件(echart.vue):
<template>
<div :ref="elId" class="box"></div>
</template>
<script>
//引入uuid文件
import uuidv1 from 'uuid/v1'
export default {
name: "echart",
data () {
return {
elId: 'echartid',
}
},
created(){
this.elId = uuidv1() //获取随机id
},
computed: {
option() {
let _this = this;
let obj ={
title: {
text: ''
},
tooltip: {
trigger: 'axis',
axisPointer : { // 坐标轴指示器,坐标轴触发有效
type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
dataZoom : [ {
// start:0,//默认为0
// end: 100-1500/31,//默认为100
type: 'slider',
show: true,
// start : 100,
start : (100-(5/20)*100),//默认展示6条;20指的是x轴类目数组的长度;
end : 100,
xAxisIndex: [0,1],
handleSize: 0,//滑动条的 左右2个滑动条的大小
// height: 10,//组件高度
// left: '10%', //左边的距离
// right: '10%',//右边的距离
height:15,
bottom: '12.5%',//右边的距离
borderColor: "#fff",
fillerColor: '#269c