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>
相关推荐
阿珊和她的猫1 小时前
v-scale-scree: 根据屏幕尺寸缩放内容
开发语言·前端·javascript
gnip6 小时前
vite和webpack打包结构控制
前端·javascript
草梅友仁7 小时前
草梅 Auth 1.4.0 发布与 ESLint v9 更新 | 2025 年第 33 周草梅周报
vue.js·github·nuxt.js
烛阴8 小时前
前端必会:如何创建一个可随时取消的定时器
前端·javascript·typescript
萌萌哒草头将军9 小时前
Oxc 最新 Transformer Alpha 功能速览! 🚀🚀🚀
前端·javascript·vue.js
武昌库里写JAVA9 小时前
JAVA面试汇总(四)JVM(一)
java·vue.js·spring boot·sql·学习
1024小神10 小时前
nextjs项目build导出静态文件
前端·javascript
parade岁月10 小时前
JavaScript 日期的奇妙冒险:当 UTC 遇上 el-date-picker
javascript
是一碗螺丝粉10 小时前
拯救你的app/小程序审核!一套完美避开审核封禁的URL黑名单机制
前端·javascript·微信小程序
littleding10 小时前
Vue3之计算属性
前端·vue.js