echarts绘制电量柱状图

话不多说,直接上代码:

<template>
  <div id="modId" class="chart"></div>
</template>
  
    <script>
import * as echarts from "echarts";

export default {

  data() {
    return {};
  },
  mounted() {
    this.drawChart();
  },
  methods: {
    drawChart() {
      var myData = ["西安", "渭南", "宝鸡"];
      var databeast = [38, 59, 62];
      let option = {
        backgroundColor: "rgba(2,58,122,0.3)",
        tooltip: {
          trigger: "axis",
          formatter: "{b0}: {c0}㎡",
        },
        xAxis: {
          type: "category",
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            show: true,
            margin: 8,
            textStyle: {
              color: "rgba(255,255,255,0.5)",
              fontSize: 12,
            },
          },
          data: myData,
        },
        yAxis: {
          type: "value",
          name: "单位:人次",
          axisLine: {
            show: false,
          },
          //y轴分割线
          axisTick: {
            show: false,
          },
          position: "center",
          //y轴标签
          axisLabel: {
            show: true,
            color: "rgba(255,255,255,0.5)",
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "rgba(255,255,255,0.5)",
              width: 1,
              type: "dashed",
            },
          },
        },
        series: [
          // 真实数据
          {
            type: "pictorialBar",
            symbol: "rect",
            barWidth: "25px",
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
                  {
                    offset: 0,
                    color: "#003190",
                  },
                  {
                    offset: 1,
                    color: "#26E1FF",
                  },
                ]),
              },
            },
            data: databeast,
          },
          {
            //辅助方格图形
            name: "辅助值",
            type: "pictorialBar",
            barWidth: "25px",
            symbol: "rect",
            symbolRepeat: "true",
            symbolMargin: "70%",
            symbolSize: ["100%", "15%"],
            symbolOffset: ["0%", "0%"],
            symbolRepeat: true,

            itemStyle: {
              normal: {
                color: "rgba(2,58,122,0.9)",
              },
            },
            data: databeast,
            z: 2,
          },
        ],
      };
      const chart = echarts.init(document.getElementById('modId'));
      // 监听窗口的 resize 事件
      window.addEventListener("resize", function () {
        chart.resize();
      });
      chart.setOption(option);
    },
  },
};
</script>
  
    <style>
.chart {
  width: 100%;
  height: 215px;
}
</style>
  

附加项:

echarts还可以根据页面缩放进行缩放

 const chart = echarts.init(document.getElementById(this.modId));
      // 监听窗口的 resize 事件
      window.addEventListener("resize", function () {
        chart.resize();
      });
      chart.setOption(option);

 效果图:

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
可以使用 ECharts绘制堆叠柱。首先,你需要引入 ECharts 库,并创建一个容器来展示表。接下来,配置表的数据和样式,最后将配置好的表渲染到容器中即可。 以下是一个简单的示例代码,演示如何使用 ECharts 绘制堆叠柱: ```html <!DOCTYPE html> <html> <head> <title>堆叠柱</title> <script src="https://cdn.staticfile.org/echarts/5.0.2/echarts.min.js"></script> </head> <body> <div id="chart" style="width: 600px; height: 400px;"></div> <script> // 初始化表 var myChart = echarts.init(document.getElementById('chart')); // 配置表数据 var option = { title: { text: '堆叠柱示例' }, tooltip: { }, legend: { data: ['类别1', '类别2', '类别3'] }, xAxis: { data: ['数据1', '数据2', '数据3', '数据4', '数据5'] }, yAxis: { }, series: [ { name: '类别1', type: 'bar', stack: '总量', data: [120, 132, 101, 134, 90] }, { name: '类别2', type: 'bar', stack: '总量', data: [220, 182, 191, 234, 290] }, { name: '类别3', type: 'bar', stack: '总量', data: [150, 232, 201, 154, 190] } ] }; // 渲染表 myChart.setOption(option); </script> </body> </html> ``` 在上述代码中,`option` 对象定义了表的各种配置项,包括标题、提示框、例、X 轴、Y 轴和系列数据。具体可以根据你的需求进行修改。 注意:在使用上述代码时,需要确保网络环境可以访问到 ECharts 库文件。你可以将 `https://cdn.staticfile.org/echarts/5.0.2/echarts.min.js` 替换为你自己的 ECharts 库文件路径。 希望以上内容对你有所帮助!如有需要,请随时提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值