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,
          },
        ],
      };

实现效果:

相关推荐
海上彼尚11 分钟前
Nodejs也能写Agent - 16.LangGraph篇 - 条件分支与循环
前端·后端·langchain·node.js
To_OC1 小时前
从 “卡死半天” 到 “打字机效果”:大模型流式输出前端实现全记录
前端·javascript·llm
SoaringHeart2 小时前
Flutter最佳实践:键盘辅助视图输入框天添加图片附件
前端·flutter
kyriewen2 小时前
我看完这篇安全论文——AI推荐的npm包,92%是编出来的
前端·javascript·ai编程
小心我捶你啊3 小时前
数据采集和Web解锁不是一回事,从用途到规则区分
前端·爬虫·网络协议
hunterandroid4 小时前
[鸿蒙从零到一] ArkUI 基础组件实战:Text、Image、Button 与 TextInput
前端
fsssb4 小时前
Chromium 源码学习笔记(五):一次点击,在进入 JS 之前先经历了什么?
前端
hunterandroid4 小时前
WorkManager 可靠性实战:唯一任务、重试与幂等设计
android·前端
鹿目4 小时前
使用 Vant CLI 搭建 UI 组件库:从 H5 到小程序跨平台
前端·javascript