vue3 中使用echarts图表——柱状图

柱状图是比较常用的图形结构,所以我先收集一些精美的柱状图

一、柱状图:设置圆角和颜色

html 复制代码
<template>
  <div class="box" ref="chartDom"></div>
</template>
<script setup>
import { ref, onMounted } from "vue";
import * as echarts from "echarts";
let chartDom = ref(null); //注意变量名 和 ref名字要对应
onMounted(() => {
  initChart();
});

const initChart = () => {
  var myChart = echarts.init(chartDom.value);
  var option = {
    tooltip: {
      // 鼠标悬浮提示数据
      trigger: "axis",
      backgroundColor: "rgba(32, 33, 36,.7)",
      borderColor: "rgba(32, 33, 36,0.20)",
      borderWidth: 15,
      textStyle: {
        // 文字提示样式
        color: "#fff",
        fontSize: "12",
      },
      axisPointer: {
        // 坐标轴虚线
        type: "cross",
        label: {
          backgroundColor: "#6a7985",
        },
      },
    },

    // },
    grid: {
      // 控制图表的位置
      left: "5%",
      right: "5%",
      top: "18%",
      bottom: "5%",
      containLabel: true,
    },
    xAxis: {
      axisLabel: {
        // X轴线 标签修改
        textStyle: {
          color: "white", //坐标值得具体的颜色
          fontSize: "10",
        },
      },
      data: ["A", "B", "C", "D", "E", "F"],
    },
    yAxis: {
      axisLabel: {
        // y轴线 标签修改
        textStyle: {
          color: "white", //坐标值得具体的颜色
        },
      },
    },
    series: [
      {
        data: [2549, 12421, 2637, 3146, 15189, 9562],
        type: "bar",
        barWidth: "48%", //调整柱状图宽度
        itemStyle: {
          normal: {
            /*--------设置柱形图圆角 [左上角,右上角,右下角,左下角]-------------*/
            borderRadius: [12, 12, 0, 0],
            /*--------设置柱形图渐变色 -------------*/
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: "rgba(0,244,255,1)",
              },
              {
                offset: 1,
                color: "rgba(0,77,167,1)",
              },
            ]),
          },
        },
      },
    ],
  };
  option && myChart.setOption(option);
};
</script>

<style scoped>
.box {
  width: 24vw;
  height: 60vh;
  background-color: #031a67;
}
</style>
相关推荐
胡萝卜术3 小时前
从API调用到手写LRU:力扣146「LRU缓存」的哈希表+双向链表终极进化之路
前端·javascript·面试
科技道人3 小时前
记录 默认置灰/禁用 app ‘Search Engine Selector‘ 的disable按钮
开发语言·前端·javascript
碎碎念_4928 小时前
SpringBoot + Vue 前后端分离从 0 到 1 完整环境配置流程
vue.js·spring boot·后端
shuaijie05189 小时前
强制修改调用接口的api地址。
javascript·vue.js·ecmascript
JerrySir9 小时前
恶意 npm 包只活了 17 分钟:技术面试里,为什么“升级依赖”还不算止血?
javascript·安全
白帽小阳9 小时前
2026前端面试题!(附答案及解析)
javascript·网络·python·安全·web安全·网络安全·护网行动
这是个栗子9 小时前
前端开发中的常用工具函数(八)
开发语言·前端·javascript
Hilaku9 小时前
Vue 和 React 真正的差距,不在语法,而在团队犯错成本
前端·javascript·程序员
研☆香10 小时前
为什么变量声明在赋值前也能使用?—— 深入理解 JavaScript 变量提升与作用域
开发语言·前端·javascript
柯克七七10 小时前
我把 bug 修得太干净了,测试组以为这个模块本来就没问题
前端·javascript·typescript