javascript - Vue-Apexcharts 饼图总数不显示

我试图在我的饼图中心显示一些元素的总数,但到目前为止我还没有在设置中找到这个选项。我该怎么做:

我当前的代码:

checksChart: {
  options: {
    colors: ['#E60B13', '#1F1E1E', '#6D6D6D', '#CECECE', 'rgba(255,87,93,.77)'],
    legend: {
      fontSize: '14px',
      fontFamily: 'Helvetica, Arial',
      fontWeight: 400,
      itemMargin: {
        vertical: 10
      },
      formatter: function(seriesName, opts) {
        return '<div class="legend-info">' + '<span>' + seriesName + '</span>' + '<span>' + opts.w.globals.series[opts.seriesIndex] + '</span>' + '</div>'
      }
    },
    dataLabels: {
      enabled: false,
    },
    labels: ['data', 'data', 'data', 'data', 'data'],

  },
  series: [400, 400, 400, 400, 400]
},
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<vue-apex-charts type="donut" :options="checksChart.options" :series="checksChart.series"></vue-apex-charts>

这是我目前所拥有的:

最佳答案

基于Apex Chart Documentation , 你需要使用 plotOptions 来显示圆环图中的数据总数。

所以你需要使用like,

chartOptions: function() {
return {
    colors: ['#E60B13', '#1F1E1E', '#6D6D6D', '#CECECE', 'rgba(255,87,93,.77)'],
    legend: {
      fontSize: '14px',
      fontFamily: 'Helvetica, Arial',
      fontWeight: 400,
      itemMargin: {
        vertical: 10
      },
      formatter: function(seriesName, opts) {
        return '<div class="legend-info">' + '<span>' + seriesName + '</span>' + '<span>' + opts.w.globals.series[opts.seriesIndex] + '</span>' + '</div>'
      }
    },
    dataLabels: {
      enabled: false,
    },
    labels: ['data', 'data', 'data', 'data', 'data'],

     plotOptions: {
          pie: {
            donut: {
              labels: {
                show: true,
                name: {
                  show: true,
                  fontSize: '22px',
                  fontFamily: 'Rubik',
                  color: '#dfsda',
                  offsetY: -10
                },
                value: {
                  show: true,
                  fontSize: '16px',
                  fontFamily: 'Helvetica, Arial, sans-serif',
                  color: undefined,
                  offsetY: 16,
                  formatter: function (val) {
                    return val
                  }
                },
                total: {
                  show: true,
                  label: 'Total',
                  color: '#373d3f',
                  formatter: function (w) {
                    return w.globals.seriesTotals.reduce((a, b) => {
                      return a + b
                    }, 0)
                  }
                }
              }
            }
          }
        },
          series: [400, 400, 400, 400, 400]
      }
    },

在上面的代码中,系列的总和是通过使用 seriesTotals.reduce 来实现的,

   total: {
     show: true,
     label: 'Total',
     color: '#373d3f',
     formatter: function (w) {
       return w.globals.seriesTotals.reduce((a, b) => {
           return a + b
       }, 0)
      }
    }

Working Vue Apex donut codepen

https://stackoverflow.com/questions/60667546/

相关文章:

oracle - 使用 ALTER TABLE 在 ORACLE 中添加多个约束

azure - 如何在Azure Pipelines的步骤中使用变量作为条件?

linux - 粘贴到终端/fish shell : [200~ and [201~ 时出现奇怪的字

regex - Ansible 列表变量和选择过滤器以忽略匹配项

ios - 我在使用 npm run ios 命令时遇到错误

css - react-pdf 中的样式显示异常行为

oracle - PL/SQL RAISE_APPLICATION_ERROR 参数问题

javascript - 在 Promise 完成后让 React 重新渲染

python - 类型错误 : _deserialize() got an unexpected k

c# - 帮助解决ASP.NET Core 3.1 Application中的 'There is