柱形图--自己记录

效果

option代码为:

barChartOptions: {
        color: ["#FFC833", "#33B9FF", "#36FFD7"],
        grid: {
          left: 20,
          right: 20,
          bottom: 10,
          top: 40,
          containLabel: true,
        },
        tooltip: {
          trigger: "axis",
        },
        legend: {
          top: 0,
          icon: "rect",
          textStyle: {
            color: "#e1e4ea",
          },
          itemWidth: 14,
          itemGap: 34,
          data: ["计划销量(吨)", "实际销量(吨)", "上年同期销量(吨)"],
        },
        xAxis: {
          axisLine: {
            show: true,
            lineStyle: {
              color: "#215d8b",
            },
          },
          axisTick: {
            lineStyle: {
              color: "#215d8b",
            },
          },
          axisLabel: {
            color: "#ccdef3",
          },
          data: [],
        },
        yAxis: {
          axisLine: {
            show: true,
            lineStyle: {
              color: "#215d8b",
            },
          },
          axisTick: null,
          splitLine: {
            lineStyle: {
              color: "#205787",
            },
          },
          axisLabel: {
            color: "#ccdef3",
          },
        },
        series: [
          {
            name: "计划销量(吨)",
            type: "bar",
            barWidth: 10,
            label: {
              show: false,
              position: "top",
              color: "#fff",
            },
            data: [],
          },
          {
            name: "实际销量(吨)",
            type: "bar",
            barWidth: 10,
            label: {
              show: false,
              position: "top",
              color: "#fff",
            },
            data: [],
          },
          {
            name: "上年同期销量(吨)",
            type: "bar",
            barWidth: 10,
            label: {
              show: false,
              position: "top",
              color: "#fff",
            },
            data: [],
          },
        ],
      },

      barChart: null,

方法使用:

mounted() {
    this.initBarChart();
    this.setBarChart();
    window.addEventListener("resize", this.resize);
  },
  beforeDestroy() {
    window.removeEventListener("reisze", this.resize);
  },
  methods: {
    initBarChart() {
      if (!this.$refs["bar"]) return;
      this.barChart = echarts.init(this.$refs["bar"]);
      this.barChart.setOption(this.barChartOptions);
    },
    setBarChart() {
      if (!this.barChart) return;
      this.barChartOptions.xAxis.data = new Array(12)
        .fill("")
        .map((item, index) => index + 1 + "月");
      this.barChartOptions.series[0].data = new Array(12)
        .fill("")
        .map(() => Math.floor(Math.random() * 10000));
      this.barChartOptions.series[1].data = new Array(12)
        .fill("")
        .map(() => Math.floor(Math.random() * 10000));
      this.barChartOptions.series[2].data = new Array(12)
        .fill("")
        .map(() => Math.floor(Math.random() * 10000));
      this.barChart.setOption(this.barChartOptions);
    },
    resize() {
      this.barChart?.resize();
    },
  },

随机生成的数据,仅作参考,自己记录便于以后直接拿来使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值