vue-draggable-resizable-gorkys与v-chart使用与总结

实现效果:
实现图表的二次封装以及表格的自由拖动,缩放功能
图片描述
图片描述vue

先贴出两个组件的地址:
vue-draggable-resizable-gorkysgit

v-chartgithub

图标的二次封装
这里咱们先作一个简单的封装
好比标题+图表的形式📈echarts

<div class="chartcontainer">
    <div>{{diyposition.title}}</div>
    <ve-line :data="chartData[0]" width="100%" height="100%" :judge-width="true" ref="mychart" :colors="colors"></ve-line>
  </div>

尤为说明一下这里的:judge-width="true"属性
若是不设置这个属性值为true的话 表格颇有可能没有办法获取到初始宽度this

另外,若是要实现表格宽度根据父组件的宽度自适应的话
咱们要使用vue的ref属性
在父组件中监听父组件宽度的变化
一旦监听到宽度发生了变化,就调用子组件的方法spa

this.$refs.mychart.echarts.resize();

这样就能结合咱们的vue-draggable-resizable-gorkys组件
实现图表的宽高自适应code

关于图表的配色
咱们能够本身定义一个颜色组:blog

colors: [
        "#61a0a8",
        "#d48265",
        "#91c7ae",
        "#749f83",
        "#ca8622",
        "#bda29a",
        "#6e7074",
        "#546570",
        "#c4ccd3"
      ]
:colors="colors"

这样就能够完成图表的配色了图片

vue-draggable-resizable-gorkys组件的使用get

<vdr
        :active="false" //肯定组件是否应处于活动状态。
        :w="200px"
        :h="200px"
        :resizable="ifresizable"//定义组件应该能够调整大小。
        :draggable="ifdraggable"//定义组件应该是否可拖动。
        v-on:dragging="onDrag"//每当拖动组件时调用。
        v-on:resizing="onResize"//每当组件调整大小时调用。
        @resizestop="onResizstop(index)"
        @dragstop="onDragstop(index)"//每当组件中止拖动时调用。
      >
         <LineChartBlock
          :chartData="charts.blockdata[index].chartdata"
          :diyposition="item"
          :changesizewidth="width"
          :changesizeheight="height"
          :colors="colors"
          v-if="charts.blockdata[index].type==1"
        ></LineChartBlock>
      </vdr>
相关文章
相关标签/搜索