echarts中横向柱状图的数字在条纹上方

实现效果: 数字在条纹的上方

实现方法:这些数字是用新添加一个坐标轴来实现的

直接添加坐标轴数字显示是在条纹的正右边

所以需要配置一下偏移

完整代码

javascript 复制代码
var option = {
      grid: {
        left: "3%",
        right: "4%",
        bottom: "3%",
        containLabel: true,
      },
      xAxis: {
        type: "value",
        boundaryGap: [0, 0.01],
        axisLine: {
          show: false,
        },
        axisLabel: {
          show: false,
        },
        splitLine: {
          show: true,
          lineStyle: {
            color: "#121f33",
          },
        },
      },
      yAxis: [
        {
          type: "category",
          data: ["aa", "bb", "cc", "dd"],

          axisLine: {
            show: true,
            lineStyle: {
              color: "#2a4661",
            },
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            color: "#b8babd",
          },
        },
        {
          type: "category",
          position: "right",
          offset: -40,
          inverse: false,
          axisTick: "none",
          axisLine: "none",
          show: true,
          axisLabel: {
            textStyle: {
              height: 30,
              width: 30,
              padding: [0, 0, 10, 0],
              color: "#03d0d4",
              fontSize: "16",
            },
          },
          //------------------右侧展示的具体内容----------------------------
          data: [
            {
              value: "89%",
              textStyle: {
                color: "#03ced1",
                verticalAlign: "bottom",
              },
            },
            {
              value: "58%",
              textStyle: {
                color: "#03ced1",
                verticalAlign: "bottom",
              },
            },
            {
              value: "66%",
              textStyle: {
                color: "#03ced1",
                verticalAlign: "bottom",
              },
            },
            {
              value: "74%",
              textStyle: {
                color: "#03ced1",
                verticalAlign: "bottom",
              },
            },
          ],
        },
      ],
      series: [
        {
          type: "bar",
          showBackground: true,
          backgroundStyle: {
            color: "rgba(13, 32, 66, 0.5)",
            borderRadius: 10,
          },
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
              { offset: 0, color: "#021a52" },
              { offset: 0.5, color: "#019cb5" },
              { offset: 1, color: "#00fdfe" },
            ]),
            borderRadius: 10,
          },
          barWidth: "20",

          data: [89, 58, 66, 74],
        },
      ],
    };

放在实例中运行即可

https://echarts.apache.org/examples/zh/editor.html?c=pie-simple

相关推荐
老虎06271 分钟前
JavaWeb前端(HTML,CSS具体案例)
前端·css·html
Mintopia6 分钟前
一个月速成 AI 工程师:从代码小白到智能工匠的修炼手册
前端·javascript·aigc
Mintopia10 分钟前
Next.js 全栈:接收和处理请求
前端·javascript·next.js
袁煦丞43 分钟前
2025.8.18实验室【代码跑酷指南】Jupyter Notebook程序员的魔法本:cpolar内网穿透实验室第622个成功挑战
前端·程序员·远程工作
Joker Zxc1 小时前
【前端基础】flex布局中使用`justify-content`后,最后一行的布局问题
前端·css
无奈何杨1 小时前
风控系统事件分析中心,关联关系、排行、时间分布
前端·后端
Moment1 小时前
nginx 如何配置防止慢速攻击 🤔🤔🤔
前端·后端·nginx
晓得迷路了1 小时前
栗子前端技术周刊第 94 期 - React Native 0.81、jQuery 4.0.0 RC1、Bun v1.2.20...
前端·javascript·react.js
江城开朗的豌豆1 小时前
React Native 实战心得
javascript