echarts图表相关 电量进度图

javascript 复制代码
//eachets 社区样式调整
var category = [
        {
          value: 47.32,
          series: "性别",
          name: "女生",
        },
        {
          value: 52.68,
          series: "性别",
          name: "男生",
        },
      ]
var grid = {
  left: 80,
  top: 20, 
  right: 80,
  bottom: 15,
}
var total = 100
var datas = category.map((item) => item.value);
option = {
    backgroundColor: '#0e202d',
        xAxis: {
          max: 200,
          splitLine: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
        grid: this.grid,
        yAxis: [
          {
            type: "category",
            inverse: true, // 根据需要设置为 true 或 false
            data: category.map((item) => item.name),
            axisLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            axisLabel: {
              show: false,
            },
          },
        ],
        series: [
          {
            // 内
            type: "bar",
            barWidth: 9,
            symbolOffset: [5, 5],
            symbolSize: [3, 13],
            legendHoverLink: false,
            silent: true,
            itemStyle: {
              normal: {
                color: (params) => {
                  var color;
                  color = {
                    type: "linear",
                    x: 0,
                    y: 0,
                    x2: 1,
                    y2: 0,
                    colorStops: [
                      {
                        offset: 0,
                        color: '#42B5F2', // 0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: '#44DCE2', // 100% 处的颜色
                      },
                    ],
                  };
                  return color;
                },
              },
            },
            label: {
              normal: {
                formatter: "{b}",
                textStyle: {
                  color: "#FFFFFF",
                  fontSize: 13,
                },
                position: "left",
                distance: 5, // 向右偏移位置
                show: true,
              },
            },

            // label: {
            //   show: true,
            //   position: "insideBottomLeft",
            //   // distance: 20,
            //   offset: this.labeloffset,
            //   fontSize: 13,
            //   color: "#CFDEED",
            //   formatter: "{b}",
            // },
            data: category,
            z: 1,
            animationEasing: "elasticOut",
          },
          {
            // 分隔
            type: "pictorialBar",
            itemStyle: {
              normal: {
                color: "#1E4067",
              },
            },
            symbolRepeat: "fixed",
            symbolMargin: 2,
            symbol: "rect",
            symbolClip: true,
            symbolSize: [3, 13],
            symbolPosition: "start",
            symbolOffset: [1, -1],
            symbolBoundingData: total,
            data: new Array(category.length).fill(total),
            z: 2,
            animationEasing: "elasticOut",
          },
        //   {
        //     // 分隔
        //     type: "pictorialBar",
        //     itemStyle: {
        //         normal: {
        //             color: "#07314a"
        //         }
        //     },
        //     symbolRepeat: "fixed",
        //     symbolMargin: 2,
        //     symbol: "rect",
        //     symbolClip: true,
        //     symbolSize: [3, 13],
        //     symbolPosition: "start",
        //     symbolOffset: [1, -1],
        //     symbolBoundingData: total,
        //     data: [total, total, total, total],
        //     z: 2,
        //     animationEasing: "elasticOut",


        // },
          {
            // 外边框
            type: "pictorialBar",
            symbol: "rect",
            symbolBoundingData: total,
            itemStyle: {
              normal: {
                color: "none",
              },
            },
            label: {
              normal: {
                formatter: (params) => {
                  return params.data;
                },
                textStyle: {
                  color: '#fff',
                  fontSize: 20,
                  fontFamily: "D-DIN",
                },
                position: "right",
                distance: 5, // 向右偏移位置
                show: true,
              },
            },
            // label: {
            //   normal: {
            //     formatter: (params) => {
            //       var text;
            //       text = "{b|" + params.value + "}" + "{a|%}";
            //       return text;
            //     },
            //     rich: {
            //       a: {
            //         color: "#D8F0FF",
            //         fontSize: 12,
            //         align: "center", // 居中文本
            //         lineHeight: 20,
            //       },
            //       b: {
            //         color: "#37E6FD",
            //         fontSize: 16,
            //         lineHeight: 20,
            //         fontFamily: "D-DIN",
            //         align: "right", // 右对齐文本
            //       },
            //     },
            //     position: "insideBottomRight",
            //     //  distance: 20,
            //     offset: this.labeloffset2,
            //     fontSize: 13,
            //     show: this.showValue,
            //   },
            // },
            data: datas,
            z: 5,
            animationEasing: "elasticOut",
          },
          {
            name: "外框",
            type: "bar",
            barGap: "-120%", // 设置外框粗细
            data: new Array(category.length).fill(total), // 创建一个长度与 category 相同的数组,每个元素都是 total
            barWidth: 13,
            itemStyle: {
              normal: {
                color: "transparent", // 填充色
                barBorderColor: '#44DAE2', // 边框色
                barBorderWidth: 1, // 边框宽度
                barBorderRadius: 2, // 圆角半径
                label: {
                  // 标签显示位置
                  show: false,
                  position: "top", // insideTop 或者横向的 insideLeft
                },
              },
            },
            z: 5,
          },
        ],
      };

实现效果:

相关推荐
mldong25 分钟前
你的 Vue3 项目也能有钉钉同款审批流设计器:npm 装包,10 分钟画出第一条审批流
前端·vue.js
2分钟速写快排1 小时前
什么是 RAG?如何用 RAG 实现一个用户记忆?
前端·后端·ai编程
passerby60612 小时前
如何自己造一个时间处理库
前端·javascript·github
走到天涯海角3 小时前
react里面的长列表渲染优化
前端·react.js·前端框架
小羊没烦恼!3 小时前
Hello Web API系列教程——Web API与国际化
java·服务器·前端·javascript·php
北岛贰3 小时前
迷茫焦虑期,我做了一个带支付带官网的 AI 聊天虚拟恋人 App
前端·人工智能·后端
mayaairi5 小时前
Vue2 组件通讯(三):全局事件总线、PubSub、插槽与组件实例属性
前端·javascript·vue.js
kyriewen5 小时前
面试官问我:AI 都能写代码了,前端凭什么还值 25K
前端·javascript·人工智能
风骏时光牛马6 小时前
AI源码分析:拆解模型底层实现逻辑
前端
IT_陈寒6 小时前
React子组件莫名其妙重渲染?你可能漏了这个Hook
前端·人工智能·后端