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

实现效果:

相关推荐
WebInfra10 分钟前
Rspack 2.1 发布:React Compiler 提速 10 倍!
前端
李明卫杭州15 分钟前
CSS 媒体查询详解:一文掌握响应式设计的核心技术
前端
lichenyang4531 小时前
从 H5 按钮到 OpenHarmony 能力调用:我如何理解 ASCF 的运行链路
前端
下家1 小时前
我放弃了 Vue/React,选择自研框架
前端·前端框架
Asize2 小时前
HTML5 Canvas 基础:从按帧动画到 ECharts 数据可视化
前端·javascript·canvas
默_笙2 小时前
🎄 后端给我一堆扁平数据,我 10 行代码把它变成了树
前端·javascript
Mahut2 小时前
我用 Electron + FFmpeg 做了一个本地视频处理工作站 ClipForge
前端·ffmpeg·electron
前端Hardy2 小时前
又一个 AI 神器火了!
前端·javascript·后端
锋行天下2 小时前
我试图优化 Vite 的拆包,结果首屏慢了 10 倍
前端·vue.js·架构
PBitW2 小时前
GPT训练我的第二天,我表示不过如此!!!😕😕😕
前端·javascript·面试