vue+vant+vue-echarts竖版图表

<template>
  <div id="echartsBox">
    <topNav :title_name="'图表'"></topNav>
    <v-chart class="chart echarts" :option="option_column" ref="echartsRef" />
  </div>
</template>
<script>
import topNav from "../../components/topNavbar/index.vue";
import { getDeviceData, getCameraData } from "../../api/index.js";
//可全局也可在要使用的文件中用
import { use } from "echarts/core";
import { CanvasRenderer } from "echarts/renderers";
import { PieChart } from "echarts/charts";
import {
  TitleComponent,
  TooltipComponent,
  LegendComponent,
} from "echarts/components";
import ECharts, { THEME_KEY } from "vue-echarts";

use([
  CanvasRenderer,
  PieChart,
  TitleComponent,
  TooltipComponent,
  LegendComponent,
]);

export default {
  name: "echartsBox",
  components: {
    "v-chart": ECharts,
    topNav,
  },
  provide: {
    [THEME_KEY]: "dark",
  },
  data() {
    return {
      id: this.$route.query.id,
      option_column: {
        // title: { text: "测试" },
        tooltip: {},
        xAxis: {
          data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        },
        yAxis: {},
        series: [
          {
            name: "销量",
            type: "bar",
            data: [5, 20, 36, 10, 10, 20],
          },
        ],
      },
    };
  },
  computed: {},
  mounted() {
    this.handleResize();
    window.addEventListener("resize", this.handleResize);
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.handleResize);
  },
  created() {
    // this.fetchData();
  },
  watch: {
    "$route.query.id": {
      handler: function () {
        //特别注意,不能用箭头函数,箭头函数,this指向全局
        // this.fetchData();
      },
      deep: true, //深度监听
    },
  },
  methods: {
    handleResize() {
      const chartEl = this.$refs.echartsRef.$el;
      chartEl.style.width = "100%"; // 设置宽度为100%
      // this.$refs.echartsRef.echartsInstance.resize(); // 调用resize方法更新图表尺寸
    },
    // 获取设备数据
    async fetchData() {
      let res = await getDeviceData({
        standId: this.id,
        userId: window.sessionStorage.getItem("userId"),
      });
      if (res.code == 0) {
        this.pageData = res.data;
        console.log(res.data);
      } else {
        return;
      }
    },
  },
};
</script>
<style lang="stylus">
#echartsBox {
  .echarts {
    height: 100vw;
    width: calc(100vh - 2.5rem);
    transform: rotate(90deg);
    background: #000;
    border: none;
  }
}
</style>

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值