echarts柱状统计图改为尖峰

效果

在这里插入图片描述
正常的柱状图是这样的
在这里插入图片描述
首先我们需要把柱子变成尖峰

重要的代码 把每一根柱子type设成 pictorialBar 然后加上 symbol

   type: 'pictorialBar',
   symbol:'path://M0,10 L10,10 C5.5, 4 5.5,1 5,0 C4.5,1 4.5, 4 0,10 z',

path://M0,10 L10,10 C5.5, 4 5.5,1 5,0 C4.5,1 4.5, 4 0,10 z

这个里面的数值可以调整尖峰的胖瘦 可以自己去尝试更换 自己尝试不多说

然后你就会发现所有的尖峰都重合到了一个位置

在这里插入图片描述

一个位置里有四个尖峰

这时需要依次挪动每一个数对应的尖峰的位置

重要代码

symbolOffset: [数值, 'left'], //可以正负值 例如 [10, 'left'] [-10, 'left'] [-10, 'center']

然后你会发现如果你设置了 尖峰顶部显示值 顶部的值 会和当时改尖峰发生重叠一样 label也会重叠

在这里插入图片描述

所以需要挪动顶部值的位置 series每一个尖峰里 label 中的offset:[0,0] 挪动与尖峰挪动值保持一致

上代码

   let option = {
        tooltip: {
          trigger: "item",
        },
        label: { show: false },
        grid: {
          top: "10%", // 可以是百分比或像素值
          right: "10%",
          bottom: "15%",
          left: "10%",
        },
        legend: {
          show: false,
        },
        xAxis: {
          type: "category",
          axisLine: {
            show: true,
            lineStyle: {
              color: "#7CDCFF",
            },
          },
          data: ["A", "B", "C"],
        },
        yAxis: {
          type: "value",
          axisLine: {
            show: true,
            lineStyle: {
              color: "#B2E7FF",
            },
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#7CDCFF",
            },
          },
        },
        color: ["#1E90FF", "#5AC76C", "#F6C555", "#EC6D3E"],
        series: [
          {
            barWidth: 20,
            name: "a",
            data: [80000, 80000, 80000],
            label: {
              // 数据上方显示数值
              show: true,
              position: "top",
              offset: [-45,0],
              textStyle: {
                color: "#fff",
              },
            },
            // type: "bar",
            // barMinHeight: 10,
            type: 'pictorialBar',
            symbol:'path://M0,10 L10,10 C5.5, 4 5.5,1 5,0 C4.5,1 4.5, 4 0,10 z',
            symbolOffset: [-45, 'left'],
            itemStyle: {
                normal: {
                    color: "#1E90FF",
                }
            },
          },
          {
            barWidth: 20,
            name: "b",
            data: [80000, 80000, 80000],
            type: 'pictorialBar',
            symbol:'path://M0,10 L10,10 C5.5, 4 5.5,1 5,0 C4.5,1 4.5, 4 0,10 z',
            symbolOffset: [-15, 'left'],
            itemStyle: {
                normal: {
                    color: "#5AC76C",
                }
            },
            label: {
              // 数据上方显示数值
              show: true,
              position: "top",
              offset: [-15,0],
              textStyle: {
                color: "#fff",
              },
            },
          },
          {
            barWidth: 20,
            name: "c",
            data: [80000, 80000, 80000],
            // type: "bar",
            type: 'pictorialBar',
            symbol:'path://M0,10 L10,10 C5.5, 4 5.5,1 5,0 C4.5,1 4.5, 4 0,10 z',
            symbolOffset: [15, 'left'],
            itemStyle: {
                normal: {
                    // 渐变色
                    color: "#F6C555",
                }
            },
            label: {
              // 数据上方显示数值
              show: true,
              position: "top",
              offset: [15,0],
              textStyle: {
                color: "#fff",
              },
            },
          },
          {
            barWidth: 20,
            data: [80000, 80000, 80000],
            name: "d",
            type: 'pictorialBar',
            symbol:'path://M0,10 L10,10 C5.5, 4 5.5,1 5,0 C4.5,1 4.5, 4 0,10 z',
            symbolOffset: [45, 'left'],
            itemStyle: {
                normal: {
                    color: "#EC6D3E",
                }
            },
            label: {
              // 数据上方显示数值
              show: true,
              position: "top",
              offset: [45,0],
              textStyle: {
                color: "#fff",
              },
            },
          },
        ],
      };
      myChart.setOption(option);
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值