echarts堆叠条形图Stacked Horizontal Bar鼠标悬停时tooltip展示每一列的总数量、修改legend样式为圆形

官网:

Examples - Apache EChartsApache ECharts,一款基于JavaScript的数据可视化图表库,提供直观,生动,可交互,可个性化定制的数据可视化图表。https://echarts.apache.org/examples/zh/editor.html?c=bar-y-category-stack

效果图:

关键代码:

完整代码:

  <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
             <div id="main1" style="width: 1000px;height:600px;"></div>
    drawLine1(){
      // 基于准备好的dom,初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById('main1'))
      // 绘制图表
      myChart.setOption( {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // Use axis to trigger tooltip
            type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
          },
          formatter(a) {
            let res = '';

            let sum = 0;
            // console.log('a=',a)

            a.forEach((item, index) => {
              if (index === 0) {
                res += `${item.axisValue}<br/>`;
              }
              sum += item.value;
              res += `${item.marker} ${item.seriesName} : ${item.value}<br/>`;
              if (index === a.length - 1) {
                res += `总数 : ${sum}`;
              }
            });
            return res;

          },
        },
        legend: {
          bottom:-5,
          icon: "circle",   //  这个字段控制形状  类型包括 circle,rect ,roundRect,triangle,diamond,pin,arrow,none
          itemWidth: 10,  // 设置宽度
          itemHeight: 10, // 设置高度
          itemGap: 40 // 设置间距
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value'
        },
        yAxis: {
          type: 'category',
          data: ['项目1', '项目2', '项目3', '项目4', '项目5', '项目6', '项目7', '项目8', '项目9', '项目10']
        },
        series: [
          {
            name: '已完成',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [320, 302, 301, 334, 390, 330, 320, 390, 330, 320]
          },
          {
            name: '施工中',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [120, 132, 101, 134, 90, 230, 210, 90, 230, 210]
          }
        ]
      });
    },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南北极之间

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值