admin管理员组文章数量:1291037
I'm trying to display the total number of some elements in the center of my pie-chart but so far I haven't been able to find this option in the settings. How can I do that:
My current code:
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=".5.17/vue.js"></script>
<vue-apex-charts type="donut" :options="checksChart.options" :series="checksChart.series"></vue-apex-charts>
I'm trying to display the total number of some elements in the center of my pie-chart but so far I haven't been able to find this option in the settings. How can I do that:
My current code:
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./ajax/libs/vue/2.5.17/vue.js"></script>
<vue-apex-charts type="donut" :options="checksChart.options" :series="checksChart.series"></vue-apex-charts>
This is what I have so far:
Share Improve this question asked Mar 13, 2020 at 9:04 Mike L.Mike L. 3434 silver badges12 bronze badges1 Answer
Reset to default 10Based on the Apex Chart Documentation, you need to use plotOptions
to display the total of data inside donut chart.
So you need to use 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]
}
},
In the above code, the sum of series is achieved by using, seriesTotals.reduce
like,
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
本文标签: javascriptVueApexcharts pie chart total not showingStack Overflow
版权声明:本文标题:javascript - Vue-Apexcharts pie chart total not showing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741502920a2382151.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论