vue echarts响应式

<template>

  <div id="main"></div>

</template>

<script>

export default {

  name: "",

  data() {

    return {

      total: "总的符合数",

      myEchart: null,

    };

  },

  methods: {

    drawChart() {

        // 这块一定要判断

      if (

        this.myEchart != null &&

        this.myEchart != "" &&

        this.myEchart != undefined

      ) {

        this.myEchart.dispose(); //销毁

      }

      this.myEchart = this.$echarts.init(document.getElementById("main"));

      let option = {

        tooltip: {

          trigger: "item",

        },

        legend: {

          top: "5%",

          left: "20",

        },

        title: [

          {

            text: 167,

            left: "30%",

            top: "45%",

            show: true,

            textStyle: {

              fontSize: 34,

              color: "#a2aee0",

            },

          },

        ],

        series: [

          {

            type: "pie",

            radius: ["50%", "70%"],

            center: ["50%", "40%"],

            avoidLabelOverlap: false,

            label: {

              normal: {

                show: true,

                position: "center",

                color: "#f00",

                formatter:

                  "{total|" + this.total + "}" + "\n\r" + "{active|共发布活动}",

                rich: {

                  total: {

                    fontSize: 35,

                    fontFamily: "微软雅黑",

                    color: "#099",

                  },

                  active: {

                    fontFamily: "微软雅黑",

                    fontSize: 16,

                    color: "#099",

                    lineHeight: 30,

                  },

                },

              },

            },

            center: ["30%", 200],

            data: [

              { value: 1048, name: "Search Engine" },

              { value: 735, name: "Direct" },

              { value: 580, name: "Email" },

              { value: 484, name: "Union Ads" },

              { value: 300, name: "Video Ads" },

            ],

          },

        ],

      };

      this.myEchart.setOption(option);

    },

  },

  mounted() {

    this.drawChart();

    // 响应式

    window.addEventListener("resize", () => {

      this.drawChart();

    });

  },

};

</script>

<style scoped>

#main {

  width: 100%;

  height: 100%;

}

</style>

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Vue2,使用Echarts实现响应式布局可以通过以下步骤进行操作。 1. 首先,需要手动调用Echarts实例的resize方法来解决页面尺寸变化时图表重新渲染排布的问题。可以在组件的mounted生命周期钩子绑定resize事件处理函数,代码如下: ```javascript resize() { this.chart.resize(); } mounted() { window.addEventListener("resize", this.resize); } ``` 2. 其次,可以通过设置组件或系列的orient或layout配置项为'horizontal'或'vertical'来实现横纵向布局的设置。这可以在组件或系列的配置进行设置,示例代码如下: ```javascript { // 组件或系列的其他配置项 orient: "horizontal", // 或者 "vertical" // 其他配置项 } ``` 3. 此外,还可以使用Media Query来设置响应式布局。可以根据页面的尺寸或其它条件,动态调整图表的配置。下面是一个具体的例子,示例代码如下: ```javascript { baseOption: { // 基础配置项 legend: { // 图例配置项 orient: "horizontal", // 其他配置项 }, series: [ { // 系列配置项 center: ["50%", "56%"], // 其他配置项 } ] }, media: [ { query: { minAspectRatio: 1, minWidth: 400 }, option: { legend: { orient: "vertical" }, series: [ { center: ["50%", "50%"] } ] } } ] } ``` 通过上述步骤和配置,可以实现Vue2Echarts响应式布局。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [在 VUE 项目,设置 echarts 图表为响应式布局](https://blog.csdn.net/qq_36291747/article/details/106992514)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值