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>
相关推荐
kyriewen10 小时前
AI 写的 React 组件,合并前必查的 6 个坏味道——每个都有代码对比
前端·javascript·react.js
Highcharts.js10 小时前
软件开发公司为什么选择 Highcharts?
前端·前端框架·echarts·数据可视化·技术选型·highcharts·图表工具
多加点辣也没关系10 小时前
JavaScript|第13章:原始类型的方法
开发语言·javascript·ecmascript
এ慕ོ冬℘゜11 小时前
深入理解 JavaScript 事件体系:Window、鼠标与键盘事件详解
开发语言·javascript·okhttp
摇滚侠12 小时前
SpringBoot3+Vue3 全套视频教程 45-51
前端·javascript·vue.js
触底反弹13 小时前
🔥 RAG 到底是怎么工作的?掰开揉碎了给你讲明白!
javascript·人工智能·后端
Hilaku13 小时前
前端大裁员背后的恐慌:我们还剩什么底牌?
前端·javascript·程序员
云空13 小时前
《Three.js 3D实例大全》
开发语言·javascript·3d·three.js
云空14 小时前
《Three.js 3D坦克对战【AI单机版】》
javascript·人工智能·3d·three.js
默_笙14 小时前
🚲 手写一个"Claude Code":我用 LangChain + ReAct 循环,让 AI 自己读文件、解释代码
前端·javascript