【前端】Echarts自适应分辨率和缩放功能

【前端】Echarts自适应分辨率和缩放功能

码农世界 2024-06-04 前端 100 次浏览 0个评论

版本

yarn add echarts@4.9.0
yarn add resize-detector@0.3.0

mixins-resize.js

import { addListener, removeListener } from 'resize-detector';
import _ from 'lodash';
export default {
  mounted() {
    const { onResize } = this;
    this.__resizeHandler = _.debounce(() => {
      if (typeof onResize === 'function') onResize();
    }, 100);
    this.$nextTick(() => {
      addListener(this.$el, this.__resizeHandler);
    });
  },
  beforeDestroy() {
    removeListener(this.$el, this.__resizeHandler);
  }
}

dataZoom.js

export const echartOptions = {
  dataZoom: [
    {
      type: 'slider', //滑动条型数据缩放组件
      start: 90, //数据窗口的起始位置百分比
      end: 100, //数据窗口的结束位置百分比
      height: 6, //数据缩放组件的高度
      bottom: 20, //数据缩放组件距离底部的距离
      realtime: false, //是否实时显示,这里是 false,表示拖动结束时才触发数据变化
      backgroundColor: '#EDF0F5', //数据缩放组件的背景色
      handleSize: 12, //滑块的大小
      //滑块的图标
      handleIcon:
        'image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAGvElEQVRYR82YS2hc5xXH/+d8333pzki+chVLlR0Zm2AY2oVjyKKvhK7aLtrVZN+WZtFnoC+y0jiQktJVaVei0BJoA1Z3Ld3WId0mgULVxqRBtuWMLMUzkWZG931OuTORbD1sybYCHWZg4N773R//8//Od84h/J996OF5lFSBy5ex8+z8PIDLw+/wMz8PpeFV0odd/4hAuyC4AXDtGVC/D+52QUFwm6L4lMYRdDCAhiFkagqyvr6ozWZTHgbuUCBVpcXF4YvZdWHCENYZwHa17xDVDHNsAgSIEYMTFc8ZK3IPRZJ8WNQ3kqIbni6iCNJsQogOV+wBQEqtFujZZ8HLy7CTAmcQwBOBT3kaGON5ieQeCywTSAzUiFOoIis5TYk0waBIuF5L1tZW8osXT+dvvAGZb0HpAaG8D9AIZmYGJgjgqsIvS4yNWdSyIh9XUN0aCkspA2OMowpWFQU0h5o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2q0HQOsF8h1h8cGxD4dYL+CWKuc4G1nrR7UTSTHnCWjY6P6rQPQwRJkkQum2mFnmXmn4Hw9ONCqep/CPyyIbNMgrYJ0QUQjwq1UZbeydSjv6N6qFKpG06Evu9OUmlmiKtsTb8EYfqRoVRvk5qXifnfmWTtUN07qKH/wHpo+5BdWHjLBsEltywHdUedSQFPE9Nphbz4KEVapQyr+Q0xXyvzbJU8947nodftIm23Ud6rzh6FRoq1WkqNBmyvB891USNCpHnxhEKmlejrDPrakYxeGZj4b1D9S1VTw9o1x0GnLNF3XSRHqql3SpHFRQaapoJiRmglnSDmSIlPAnJSFV8ixtNQOrcLbgiB96VSRcybZPSmltoxJJ3SulUtNOh0kE5Pozhy17ENVam1uAiLdbhFBF8VYVmiTkUxzkAdlkIRBIC4RExVX0aiubKJoTogQg9qNw3QixWDWg1x5ZkHtUAHhWzHt9WuqwYKw5Yogu124QYBPJMlgXi+jyz3ieEyk80U7JKVHHkpgsyDJikk8Qo/thNIKpBuF0XlmdEg4v4t9SG9/WjIUPX2WIJBA8brwa4rHNeFzfMt63ljnGUxuW6gJt2S3Bkr/AxF5qNwXeSVItVvaQl6UB+2d+ceOmzYTgnbYFNToPX1YbvEWQYOgrtjmTiGui6kmn50u29pFF2So4IckIeOmmV2z4cajbtA1curVaqwDP1whGnHIyp0VNjHv++IIXv8Fx11hf8B8c+fUjRHBs0AAAAASUVORK5CYII=',
      dataBackground: {
        //数据区域的背景配置
        lineStyle: {
          //数据区域边界线的样式配置,这里设置为透明
          opacity: 0,
        },
        areaStyle: {
          //数据区域填充样式配置,这里设置为透明
          opacity: 0,
        },
      },
      selectedDataBackground: {
        //选中数据区域的背景配置
        lineStyle: {
          //选中数据区域边界线的样式配置,这里设置为透明
          opacity: 0,
        },
        areaStyle: {
          // 选中数据区域填充样式配置,这里设置为透明
          opacity: 0,
        },
        brushStyle: {
          //选中数据区域的刷子样式配置,这里设置边框颜色为红色
          borderColor: '#f00',
        },
      },
      // fillerColor: ' #A3A1FB', //数据区域的填充颜色 紫色
      textStyle: {
        color: 'transparent', //文本颜色,这里设置为透明
      },
    },
  ],
}

使用



转载请注明来自码农世界,本文标题:《【前端】Echarts自适应分辨率和缩放功能》

百度分享代码,如果开启HTTPS请参考李洋个人博客
每一天,每一秒,你所做的决定都会改变你的人生!

发表评论

快捷回复:

评论列表 (暂无评论,100人围观)参与讨论

还没有评论,来说两句吧...

Top