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

实现效果:

相关推荐
Thomas.Sir2 小时前
Vue 3:现代前端框架的架构革命
前端·vue.js·web·大前端
源码之屋2 小时前
毕业设计源码:python网易云音乐数据分析可视化平台 Flask+ECharts 多维度数据可视化分析 人工智能 大数据 机器学习 (建议收藏)✅
人工智能·python·信息可视化·django·毕业设计·echarts·课程设计
SouthRosefinch2 小时前
三、HTML文本、语义化、列表与表格
前端·html5
清空mega2 小时前
《Vue3 模板语法与常用指令详解:插值、绑定、件、条件渲染、列表渲染一次学会》
前端·javascript·vue.js
周淳APP2 小时前
【HTTP相关及RESTful】风萧萧兮易水寒之壮士学习不复返
前端·javascript·网络·网络协议·http·restful·jsonp
gyx_这个杀手不太冷静2 小时前
OpenCode 进阶使用指南(第四章:企业级功能)
前端·ai编程
周淳APP2 小时前
【计算机网络之HTTP、TCP、UDP、HTTPS、Socket网络连接】
前端·javascript·网络·网络协议·http·前端框架
Luna-player2 小时前
将Vue 项目上传到Gitee流程步骤
前端·vue.js·gitee
柳杉2 小时前
精选10套开源数据可视化大屏项目合集 | 从 3D 地球到数字孪生
前端·javascript·数据可视化